0

I'm porting my application from traditional Nginx, PHP, Mysql on one host to a kubernetes environment.

I've been following the tutorial provided Here

The TLDR; is that you create a php-fpm processor (workload) listening on php:9000, and an nginx workload that handles the request and proxies to the FPM service. I've added a mysql:5.7.30 workload, and a phpMyAdmin workload, which interact fine.

My site loads, index.php shows up fine, and a test file with phpinfo(); executes correctly. So I know that nginx is passing the scripts to php:9000 correctly, and all my ingresses are working.

Here is where things get weird. If I load a page via browser that invokes mysqli, even just a new mysqli(...); I get an error saying:

2020/05/10 04:22:56 [error] 6#6: *12 FastCGI sent in stderr: "PHP message: PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /var/www/app/db.php on line 12
PHP message: PHP Warning: mysqli::query(): Couldn't fetch mysqli in /var/www/app/script.php on line 8
PHP message: PHP Notice: Trying to get property of non-object in /var/www/app/script.php on line 9"

But if I execute that same script on the FPM pod, it returns as expected, no errors.

My script is just performing a read, where it includes db.php which contains the mysqli connection which looks like:

  $db_host = getenv('MYSQL_HOST', true);
  $db_uname = getenv('MYSQL_USER', true);
  $db_pwd = getenv('MYSQL_PASS', true);
  $db_name=getenv('MYSQL_DB', true);
  $db = new \mysqli($db_host,$db_uname,$db_pwd,$db_name);

The \mysqli comes from this post which unfortunately didn't help.

In this case, the env variable $db_host is set to a DNS name, called mysql-host. I know that the cluster DNS is working, because I have another pod running phpMyAdmin that can authenticate to the mysql pod fine (they're all in the same namespace).

Is this a case for having Nginx and PHP co-located as opposed to separating them into services? It seems like the mysqli connection is trying to initiate on the nginx pod, which wouldn't have php or mysql on it. Both the Nginx and fpm pods have the same environment variables, which point at the same host for mysql.

Ryan
  • 433
  • 1
  • 11
  • 29
  • this is not a duplicate of that question because this same code runs fine on a server where everything is co-located. – Ryan May 10 '20 at 05:12
  • All right i googled the other error message for you – Your Common Sense May 10 '20 at 05:17
  • Except thats not at all related to my problem. My code doesn't contain any close statements. And that question isn't related to kubernetes, or fpm proxies. I've found similar solutions on my own, and they didn't address the problem. – Ryan May 10 '20 at 05:19
  • I'm not having issues with the code itself. In my post I clarified that its running fine on a traditional install. I'm running into an error with the way the mysqli call is being invoked, an I haven't found a "google-able" answer to it. – Ryan May 10 '20 at 05:25
  • So I found it for you. Don't mention it. – Your Common Sense May 10 '20 at 05:26
  • I beg my pardon. I've got pretty decent expertise in using the Google Search. Here is how it works. You see the error message in the error log. You copy the meaningful part of the error message into the buffer. You paste the error message in the address bar of your browser. You hit Enter. Usually it works. If it doesn't, look twice at the error log. May be you just copied the wrong error message. – Your Common Sense May 10 '20 at 05:50
  • Again, you’re not listening to your own advise. the answers you have provided, Ive already seen and aren’t relevant. I can quickly google words without understanding them too. I don’t fall into any of the categories of posts you’ve added here. This community used to be helpful. Don’t you think I would google before posting here? I’ve been here for at least 10 years. – Ryan May 10 '20 at 05:55
  • I don't think you provide enough details in this question for it to be different from the linked post. If you have a different issue, which the given solution doesn't address you need to edit your question and explain why the solution provided didn't work for you. Here are another relevant questions: https://stackoverflow.com/q/36378615 https://stackoverflow.com/q/55117000 https://stackoverflow.com/q/58976692 Check if they provide a better explanation of your problem. If this is not the problem, then you need to explain how you verified that the given solutions don't work for you. – Dharman May 10 '20 at 12:23
  • None of those other posts make mention of Kubernetes or the intricacies of cross pod communication, or having problems with nginx forwarding fastcgi to the php service. I thought I fairly clearly differentiated between the fact that this code works fine when it’s not in a kube environment, and as soon as I split things up into services it breaks. Is it the new norm to go through such an inquisition to post here now? I’ll try to add more details. – Ryan May 10 '20 at 13:56

0 Answers0