I'm seeing the following error in my nginx logs on my Ubuntu machine:
[crit] 14697#0: *1 connect() to unix:/home/php/run/php-fpm.sock failed (13: Permission denied) while connecting to upstream, client: x.y.z.w, server: mydomain.org, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/home/php/run/php-fpm.sock:", host: "mydomain.org"
Here are the permissions on the socket:
$ ll /home/php/run
total 8.0K
drwxr-xr-x 2 php php 4.0K Jan 10 18:56 .
drwxr-xr-x 12 php php 4.0K Jan 9 17:33 ..
srw-rw---- 1 php php 0 Jan 10 18:56 php-fpm.sock
The "nginx" process is run as the nginx user:
$ ps aux | grep nginx | grep -v grep
root 14694 0.0 0.3 88732 1784 ? Ss 19:08 0:00 nginx: master process /home/nginx/sbin/nginx -c /home/nginx/conf/nginx.conf
nginx 14697 0.0 1.0 88732 5112 ? S 19:08 0:00 nginx: worker process
I added the nginx user to the "php" group:
$ groups nginx
nginx : php
I tried restarting both nginx and php-fpm after doing so but I got the same failure. I am confused because the socket has permissions of 660, which should give read and write permissions to members of the php group. I'm also confused because the file appears writeable; if I run su - nginx and then run
$ test -w /home/php/run/php-fpm.sock ; echo $?
0
which seems to indicate that the nginx user can write to the socket. Why can't nginx write to the socket? What other information do I need to solve this problem?
Related
i have a Problem. My Website is only a White Clean Site. With no Error, like nothing there.
Running Ubuntu 16.04, NGINX and PHP5.6-fpm
/var/run/php/php5.6-fpm.sock is exists.
The Site is running before with my NGINX Settings, here is PHP location
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
try_files $uri =404;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
}
Before (Ubuntu 14.04 and PHP5-fpm) it was fastcgi_pass unix:/var/run/php/php5-fpm.sock;
But i cannot install php5-fpm anymore, cause Ubuntu 16.04 doesnt support it.
If i take a look to /var/log/nginx/error.log there is nothing! No Logs from the Site
I dont know what i can do... i tried php7.0 but also same look...
Outputs:
fpm grep
root 2214 0.0 0.1 14236 1024 pts/0 S+ 16:26 0:00 grep --color=auto fpm
root 31797 0.0 2.2 234016 22504 ? Ss 13:15 0:00 php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)
www-data 31802 0.0 7.1 280008 72224 ? S 13:15 0:02 php-fpm: pool www
www-data 31803 0.0 5.9 280888 60328 ? S 13:15 0:01 php-fpm: pool www
nginx grep
root 319 0.0 0.2 125368 3040 ? Ss 13:32 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 320 0.0 0.6 125368 6776 ? S 13:32 0:00 nginx: worker process
root 2219 0.0 0.1 14236 1020 pts/0 S+ 16:27 0:00 grep --color=auto nginx
status nginx
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2017-09-21 13:32:45 CEST; 2h 55min ago
Process: 308 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCE
Process: 316 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 313 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 319 (nginx)
CGroup: /system.slice/nginx.service
├─319 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
└─320 nginx: worker process
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[313]: nginx: [warn] server name "/var/www/*****.de/htdocs" has suspiciou
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[313]: nginx: [warn] conflicting server name "*****.de" on 0.0.0.0:80, ignored
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[313]: nginx: [warn] conflicting server name "*****.de" on 0.0.0.0:80,
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[316]: nginx: [warn] server name "/var/www/*****.de/htdocs" has suspiciou
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[316]: nginx: [warn] conflicting server name "*****.de" on 0.0.0.0:80, ignored
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal nginx[316]: nginx: [warn] conflicting server name "*****.de" on 0.0.0.0:80,
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argum
Sep 21 13:32:45 Ubuntu-1404-trusty-64-minimal systemd[1]: Started A high performance web server and a reverse proxy server.
I get 500 status on some of the php pages for Sentrifugo and to find out what
's going wrong I tried setting up error logging
The configuration can be found in this gist
However, on the pages that I get a 500, I do not see any log entries in any of these files
/var/log/php7.0-fpm.log
/var/log/php_errors.log
The worker pool log diectory is empty
anadi#foo:~$ sudo ls -ltr /var/log/php-fpm/
total 0
All I see is a 500 status logged in the access.log with no imformation at all that could help me troubleshoot
XX.XXX.XX.XX - - [13/Mar/2017:13:48:53 +0530] "GET /index.php/wizard/configuresite HTTP/2.0" 500 390 "https://foo.bar.com/index.php/wizard/managemenu" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
There's no entries in /var/log/nginx/foo/error.log neither
Update
All log directories are writable by the respective owner
anadi#foo:~$ ps -ef | grep php
root 19453 1 0 15:24 ? 00:00:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 19458 19453 0 15:24 ? 00:00:00 php-fpm: pool www
www-data 19459 19453 0 15:24 ? 00:00:00 php-fpm: pool www
anadi#foo:~$ ls -ltr /var/log/ | grep php
-rw-r--r-- 1 root root 1679 Mar 13 10:47 php_errors.log
drwxr-xr-x 2 www-data www-data 4096 Mar 13 15:23 php-fpm
-rw------- 1 root root 13590 Mar 13 15:24 php7.0-fpm.log
anadi#foo:~$ ls -ltr /var/log/php-fpm/
total 4
-rw-r--r-- 1 www-data www-data 0 Mar 13 15:23 www.error.log
-rw-r--r-- 1 www-data www-data 2041 Mar 13 15:34 www.access.log
anadi#foo:~$ ps -ef | grep nginx
root 19632 1 0 15:27 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 19633 19632 0 15:27 ? 00:00:00 nginx: worker process
www-data 19634 19632 0 15:27 ? 00:00:00 nginx: worker process
anadi#foo:~$ ls -ltr /var/www/
total 8
drwxrwxr-x 2 www-data www-data 4096 Mar 3 21:18 html
drwxr-xr-x 10 www-data www-data 4096 Mar 13 15:31 foo
anadi#foo:~$ ls -ltr /var/log/nginx/
total 16
drwxr-xr-x 2 www-data www-data 4096 Mar 13 09:58 foo
-rw-r--r-- 1 root root 1105 Mar 13 15:08 error.log
-rw-r--r-- 1 root root 5384 Mar 13 15:41 access.log
Did changes to display_errors setting as explained in one of the answers, but this still does not give any helpful log output for troubleshooting.
Here's extract of var/log/php-fpm/www.acccess.log
- - 13/Mar/2017:15:32:11 +0530 "GET /index.php" 500 /var/www/tribe/index.php 34.722 2048 57.60%
- - 13/Mar/2017:15:34:14 +0530 "GET /index.php" 500 /var/www/tribe/index.php 20.952 4096 95.46%
search for log file in your project
And In your php.ini you can find display_errors = Off make it equal On
I am not sure why, but downgrading to PHP 5 solved all of it, error logs populate as expected, and the intermittent 500 status codes have disappeared
We have created a container from this image: https://github.com/bytepark/alpine-drupal8 and connected our drupal 8 site. It seems to load just fine, but when we go to add a new field to a content-type, it fails with no error in the page. Checking /var/log/nginx/error.log I see:
2016/09/16 20:58:11 [crit] 13685#13685: *26 open()
"/var/lib/nginx/tmp/fastcgi/7/00/0000000007" failed (13: Permission
denied) while reading upstream, client: x.x.x.x, server: _, request:
"POST
/admin/structure/views/ajax/add-handler/content/page_1/field?_wrapper_format=drupal_ajax
HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host:
"x.x.x.x:8080", referrer:
"http://x.x.x.x:8080/admin/structure/views/view/content"
I have tried setting permissions to 777 on /var/lib/nginx and subfolders but that has no effect:
root#:/usr/share/nginx/html# ls -l /var/lib/nginx/
total 8
drwxrwxrwx 2 root root 4096 Sep 16 20:11 html
lrwxrwxrwx 1 root root 14 Aug 24 13:27 logs -> /var/log/nginx
lrwxrwxrwx 1 root root 22 Aug 24 13:27 modules -> /usr/lib/nginx/modules
lrwxrwxrwx 1 root root 10 Aug 24 13:27 run -> /run/nginx
drwxrwxrwx 6 nginx nginx 4096 Sep 16 20:04 tmp
root#:/usr/share/nginx/html# ls -l /var/lib/nginx/tmp
total 16
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 fastcgi
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 proxy
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 scgi
drwxrwxrwx 2 nginx nginx 4096 Sep 16 20:04 uwsgi
I've tried lots of different solutions from google but nothing seems to make any difference, is there something I am missing here?
I am getting the following error in my Nginx error.log file, what do I need to do to prevent this from happening?
2016/06/28 09:43:37 [crit] 1631#0: *1 connect() to
unix:/run/php/php5.6 fpm.sock failed (13: Permission denied) while
connecting to upstream, client: 192.168.56.1, server: my-vm, request:
"GET / HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php5.6-fpm.sock:", $host: "my-vm-1"
Nginx runs with www-data permissions. The permissions of the folder that the error message is referencing (/run/php/php5.6-fpm.sock) are as follows:
drwxr-xr-x 20 root root 700 Jun 28 09:45 run
drwxr-xr-x 2 www-data www-data 80 Jun 28 09:44 php
srw-rw---- 1 www-data www-data 0 Jun 28 09:44 php5.6-fpm.sock
The user/group of PHP (/etc/php/5.6/fpm/pool.d/www.conf) is:
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
The nginx.conf file does not have any user value set. Some people have suggested setting this to www-data, but if I set this the Nginx service won't start, hence why it is ommitted.
I fixed this by adding the following user directive to the top of my nginx.conf file:
user www-data www-data;
I am having some permission issues with Nginx and Php fastcgi when trying to get to the php file. I am using 5.5.15 and Nginx 1.6.0 in Redhat 7 .
My php file is very simple for now.
<?php
echo "\nscript owner : ".get_current_user()."\n";
$myFile = '/usr/share/nginx/html/test.log';
$fh = fopen($myFile, 'a') or die("can''t open file");
?>
Get current user will result in : "myuser"
The error that I am getting is the following:
2014/08/26 22:47:14 [error] 6424#0: *16 FastCGI sent in stderr: "PHP message: PHP Warning: fopen(/usr/share/nginx/html/test.log): failed to open stream: Permission denied in /usr/share/nginx/html/test.php on line 19" while reading response header from upstream, client: XXXXXX, server: XXXXXXX, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "XXXXXXX"
Here is the permissions for the directory /usr/share/nginx( all of the parent directories have x permissions):
drwxrwsrwx. 4 myuser myuser 4096 Aug 26 22:32 html
Running the following commands:
$ ps aux | grep "nginx: worker process"
myuser 6423 0.0 0.3 111228 3880 ? S 22:36 0:00 nginx: worker process
myuser 6424 0.0 0.5 111228 5428 ? S 22:36 0:00 nginx: worker process
myuser 6480 0.0 0.0 112640 980 pts/0 R+ 22:41 0:00 grep --color=auto nginx: worker process
$ ps aux | grep "php"
myuser 5930 0.0 0.1 128616 1860 pts/0 T 21:09 0:00 vi /etc/php-fpm.conf
myuser 5931 0.0 0.2 128628 2052 pts/0 T 21:09 0:00 vi /etc/php.ini
myuser 5933 0.0 0.1 128616 1864 pts/0 T 21:13 0:00 vi /etc/php-fpm.conf
myuser 5934 0.0 0.1 128616 1860 pts/0 T 21:14 0:00 vi /etc/php-fpm.d/www.conf
myuser 5935 0.0 0.1 128616 1864 pts/0 T 21:15 0:00 vi /etc/php-fpm.conf
root 6313 0.0 2.4 544732 25208 ? Ss 22:25 0:00 php-fpm: master process (/etc/php-fpm.conf)
myuser 6314 0.0 0.8 544732 8356 ? S 22:25 0:00 php-fpm: pool www
myuser 6315 0.0 0.8 544732 8328 ? S 22:25 0:00 php-fpm: pool www
myuser 6316 0.0 0.9 545076 9892 ? S 22:25 0:00 php-fpm: pool www
myuser 6317 0.0 0.9 544860 9452 ? S 22:25 0:00 php-fpm: pool www
myuser 6318 0.0 0.9 544860 9212 ? S 22:25 0:00 php-fpm: pool www
myuser 6483 0.0 0.0 112640 976 pts/0 R+ 22:47 0:00 grep --color=auto php
My Server looks like the following:
server {
listen 80;
root /usr/share/nginx/html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
And in the nginx.config I am using the same user: "user ec2-user;"
I have also changed the /etc/php-fpm.d/www.conf file to have the same user and group.
user = myuser
group = myuser
So, both Nginx and PHP are running on the same user "myuser".
All the directories up to where the log file and the php file are located(/usr/share/nginx/html) have x access and that user has 777 access to that html directory.
Not sure what I am missing. I have been searching online for 2 days now but no luck.
I suppose rights are correct, but you have 3 line of code in test.php, but due to error this is not true :) Check what file you run.
"in /usr/share/nginx/html/test.php on line 19"