Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
Encountered a permission denied problem while setting up a server with Ubuntu + PageSpeed + Nginx + PHP5-FPM. From the log file, the error message is
2015/10/04 23:32:41 [crit] 5107#0: *6 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xx.xxx.xxx.xxx, server: xxxxxxxxx.com, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xxx.xxx.xxx.xxx"
Diagnostic :
ls -la /var/run/php5-fpm.sock
returns
srw-rw---- 1 www-data www-data 0 Oct 4 23:29 /var/run/php5-fpm.sock
and because php5-fpm will be used by Nginx with the user nginx
instead of www-data
. Therefore, the permission, owner and owner group need to be changed to nginx
.
For PHP5-FPM under Ubuntu, modify the /etc/php5/fpm/pool.d/www.conf file.
vi /etc/php5/fpm/pool.d# vi www.conf
change
#user = www-data
#group = www-data
user = nginx
group = nginx
and
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
NOTE : IF you just change the /var/run/php5-fpm.sock file with the chmod 066 /var/run/php5-fpm.sock
command. The problem will go away momentarily before coming back again. You need to change the /etc/php5/fpm/pool.d/www.conf
file to have permanent effect.
IF your server does not have user nginx. Create one with the command below :
sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
To test if the your php5-fpm is set correctly, go to your root directory and create a php file with this content :
<?php
phpinfo();
?>
Restart php5-fpm with
service php5-fpm restart
and point your browser to your server
http://your-server-address/info.php
and if everything goes well, you should see the PHP configuration information that looks like this.
Hope this helps!
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+34.1k Golang : Call a function after some delay(time.Sleep and Tick)
+7.1k Golang : Join lines with certain suffix symbol example
+7.2k Golang : Transform lisp or spinal case to Pascal case example
+8.8k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+24.7k Golang : GORM read from database example
+20.1k Golang : Count JSON objects and convert to slice/array
+13.8k Golang : Set image canvas or background to transparent
+10.7k Golang : Select region of interest with mouse click and crop from image
+11.5k Golang : How to flush a channel before the end of program?
+7.6k Linux : How to fix Brother HL-1110 printing blank page problem
+11.6k Golang : Delay or limit HTTP requests example
+16.3k Golang : ROT47 (Caesar cipher by 47 characters) example