First of all: I'm not an expert in configuring things. This is very new for me, so, my apologies in advance.
At work we have a Centos server. The guy who worked here before installed nginx. We need to made a php site, so, obviously, I need to set up php and make it work with nginx.
Making short a very long tale, I had to replace the nginx binary with a new one (because the older was compile without fast-cgi), and I had to recompile and install php (because the new version has fpm). Then I struggle with the config files, making this nginx.conf (not all the file)
user php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
and uncomment some parameters in php-fpm (to much to detail here, but the important is that group and user are "php")
I never could start the php-fpm with the instructions of the book
sudo /usr/sbin/php-fpm start
But after look at the net, I found this
sudo /usr/local/sbin/php-fpm --fpm-config=/usr/local/etc/php-fpm.conf
This worked (I think)
I restarted nginx. But... nothings happens with php... My calls to php files (via firefox) doesn't even appear in the log (/opt/nginx/logs/error.log)
I'm really, really exhausted and lost... Could anyone help me, pleaaase.... :(
Thanks in advance
first of all check that php-fpm is listening on 9000 port: netstat -an | grep LISTEN | grep 9000 if it return something like: tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN then php-fpm works and you should check your nginx configuration. i.e. check if you defined right server_name. it should be the same as you enter it in your browser. if you use some other urls than localhost make sure you have right DNS record for this urls. mine config for php-fpm is:
this config works at many of my sites.
I believe that php-fpm and fastcgi are two separate ways of integrating nginx and PHP. I think that you need to use one method or the other. This guide for CentOS should get you in the ballpark using fastcgi. http://library.linode.com/web-servers/nginx/php-fastcgi/centos-5
I successfully followed a similar article from their library to setup Nginx/fastcgi/PHP on Ubuntu.
This works for me on nginx 0.8.54. The "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;" is probably the only thing you need to change. It uses the "root /var/www/example.com/yoursite" directive in your server config. I've had it throw errors up at me before in the past, by only serving up a white page. You can see the errors usually in /var/log/nginx/error.log. Also, did you set up php-fpm to run on TCP port or socket? Check your php-fpm.conf, I think it defaults to TCP port 9000. this nginx.org page has a whole bunch of default configurations for various open source web apps (wordpress, drupal, etc.).