0

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)

4
  • I am a step further, I installed php53 from the IUS repo. Now it says Error connecting to mysql Commented Apr 16, 2012 at 10:27
  • Install everything from EPEL repo Commented Aug 16, 2013 at 23:50
  • looks like mysql id down. Commented Aug 16, 2013 at 23:50
  • ps auxwf|grep mysql;netstat -anp|grep mysql Commented Aug 16, 2013 at 23:51

2 Answers 2

1

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!

0

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.

1
  • 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 Commented Apr 16, 2012 at 8:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.