Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to install an Nginx server with PHP and MySQL on my VPS running CentOS.

I followed this tutorial to install all the sofware.

he server is running, the virtual hosts are working, but when I try to connect to MySQL in a PHP file the server returns 502 Bad Gateway.

I am a newbie in Linus, so I don't exactly know where to find all the logs etc.

I have found this error in the virtual host log, but I don't know what it means.

2012/04/15 23:07:33 [error] 22360#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 212.45.63.107, server: @host, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "@host"

(where @host is my server)

share|improve this question
    
I am a step further, I installed php53 from the IUS repo. Now it says Error connecting to mysql –  Qurben Apr 16 '12 at 10:27
    
Install everything from EPEL repo –  GioMac Aug 16 '13 at 23:50
    
looks like mysql id down. –  GioMac Aug 16 '13 at 23:50
    
ps auxwf|grep mysql;netstat -anp|grep mysql –  GioMac Aug 16 '13 at 23:51
add comment

2 Answers 2

Looks like PHP won't able to connect to MySQL dispute which http server you use and the way you ling php to http server.

First, check if your MySQL is running and listen at all (you may forget to run it). Simply run mysql from CLI, and see if it connects. You may need to use -h host key to point mysql client to right host.

Then, try to run the simplest script (like

<?php
$link = mysql_connect('hostname', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

so you'll see what's the error. If your MySQL listen on localhost (127.0.0.1), then use 'localhost' as hostname ('hostname' in the example), if it listen in socket, then use socket path (something like ':/tmp/mysql').

Good luck!

share|improve this answer
add comment

Is there anything running on port 9000? Check the output of netstat -anp | grep :9000. It looks like PHP is either not running (or firewalled).

Is PHP itself actually running? Check the output of ps aux | grep php. If not, you should check over what you did to enable it as a service again.

share|improve this answer
    
Yes, php-cgi is listening on port 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2015/php-cgi and php-cgi is running. Serving php files is not a problem, phpinfo() is working and I have uploaded code igniter it works too. But when I connect to the database I get an error –  Qurben Apr 16 '12 at 8:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.