Nginx – Setting up nginx(Built from source) with php5-fpm

nginxphp-fpm

So am new to nginx. On Ubuntu I installed nginx using "sudo apt-get install nginx" then installed php5-fpm sudo apt get install php5-fpm. I followed the steps at: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04 and got nginx to work fine with php5-fpm.

This is the relevant section from my nginx configure file to enable fastCGI proxying.

location ~ \.php$ {

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

That works perfectly and php files run how they are suppose to.

I then downloaded nginx-1.7.3.tar.gz and built if from source:

--configure --prefix=/usr/local/nginx-1.7.3 make sudo make install

So by now I would have two installation of nginx. The first one using apt-get install nginx and this one which was built from source. I can run each one differently sudo service nginx start runs the the apt-get install version and sudo /usr/local/nginx-1.7.3/sbin/nginx runs the version built from source.

To enable fastCGI proxying on the "built from source" version I figured it's the same as the first installation of nginx so the nginx.conf file's location block for fast cgi proxying is identical to the first one.

BUT

The version that was built from source seems to not be communicating with php5-fpm so I get the error:

An error occurred

Sorry, the page you are looking for is currently unavailable.
Please try again later.

And the error log for nginx says:2014/08/03 01:31:24 [crit] 8566#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"

Due to my lack of knowledge I suspect I'm doing something really stupid but I can't seem to figure it out. Why does the "built from source" version give that error when trying to connect to files ending with .php ?

Best Answer

As zhenech pointed out, you most likely have a problem with the owner/permissions on your socket-file (/var/run/php5-fpm.sock).

In your fpm-config (e.g. /etc/php5/fpm/pool.d/www.conf), try the following:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660