Nginx PHP5.6 permission eror - php

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;

Related

nginx permission denied error on alpine drupal 8 docker image

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?

Nginx virtual hosts not working

I recorded a video https://youtu.be/dmezVzASr5A
I have:
linux ubuntu 16.04 (Lubuntu)
nginx 1.10
php7.0-fpm
php7.0
mysql 5.7
I did:
created domain /etc/hosts (test2.test)
created virtual hosts withing sites-available folder (test2.test file)
restarted, reloaded nginx server (sudo service nginx stop...restart...reload)
created symlink ln -s /etc/nginx/sites-available/test2.test /etc/nginx/sites-enabled/
symlink proof:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -ls /etc/nginx/sites-enabled
total 0
0 lrwxrwxrwx 1 root root 34 май 21 16:33 default -> /etc/nginx/sites-available/default
0 lrwxrwxrwx 1 root root 37 май 21 16:44 test2.test -> /etc/nginx/sites-available/test2.test
Problem is when i try to open in browser http://test2.test, i get:
404 Not Found
nginx/1.10.0 (Ubuntu)
This files are not opening:
index.html
test.html
index.php
within /var/www/html i have info.php with content <?php echo phpinfo(); ?>. http://localhost/info.php successfully displays php info.
My permissions:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima dima 4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data 111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data 26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data 5 май 21 16:59 test.html
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$
My virtual hosts:
server {
listen 80;
listen [::]:80;
server_name test2.test;
root /home/dima/www/nginx/test2.ru;
index index.html;
location / {
try_files $uri $uri/ =404;
#autoindex on;
}
}
nginx logs:
error.log.1:
many errors like:
2016/05/26 08:46:28 [crit] 1066#1066: *1 stat() "/home/dima/www/nginx/test2.ru/" failed (13: Permission denied), client: 127.0.0.1, server: test2.test, request: "GET / HTTP/1.1", host: "test2.test"
ls -la:
dima#dima-Lenovo-G50-30:~/www/nginx$ ls -la
total 16
drwxrwxr-x 4 dima dima 4096 май 21 13:14 .
drwxrwxr-x 10 dima dima 4096 май 21 12:52 ..
drwxrwxr-x 5 dima dima 4096 май 21 12:52 test1.ru
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 test2.ru
dima#dima-Lenovo-G50-30:~/www/nginx$
within test2.ru folder:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima dima 4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data 111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data 26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data 5 май 21 16:59 test.html
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$
UPD I have fixed. It was permissions problem. I changed some permisisions and it worked, but i don't know and remvemebr exactly what i did, but it works
Maybe you can try to give execute access to the files in that /home/dima/www/nginx/test2.ru folder. Nginx needs to execute the php files, not only read the files.

nginx: Can't connect to php-fpm socket

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?

Cannot run index.html from /var/www/html - 403 forbidden

I copied a few files from a local folder to the apache server folder /var/www/html, which includes an index.html as well.
I created a test file to check php version inside the folder and it gave the correct result of phpinfo().
But I cannot run localhost/index.html from the browser. I get the error-
Forbidden
You don't have permission to access /index.html on this server.
Apache/2.4.7 (Ubuntu) Server at localhost Port 80
I checked the owner info by running ls -l inside /var/www/html, and this is the result-
drwx--S--- 4 root www-data 4096 Mar 26 22:28 ch01
-rw-r--r-- 1 root www-data 20 Mar 26 22:16 check.php
-rw------- 1 root www-data 36911 Mar 26 22:28 fang.jpg
-rw------- 1 root www-data 2060 Mar 26 22:28 index.html
-rw-r--r-- 1 root www-data 19 Mar 26 22:28 pp.php
-rw------- 1 root www-data 1261 Mar 26 22:28 report.php
-rw------- 1 root www-data 77 Mar 26 22:28 style.css
I am trying to run the example code from head first into php and mysql.
I installed apache and php using this guide - https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
-rw------- 1 root www-data 2060 Mar 26 22:28 index.html
The file is
owned by root (who can read and write to it (rw-))
a member of the www-data group (which can't do anything with it (---))
can't be touched by the public (---)
Your webserver is almost certainly running as www-data, so you need to either:
Change the ownership of the file: chown www-data index.html or
Give the group permission to edit it: chmod 660 index.html
You have similar issues with other files.
NB: The current ownership and permissions suggests that you are using the root account to manage the files for the website. Don't do that. Create an account with more limited access for that purposes. Only run as root when you really have to.
the default location is
/var/www/
and not '
/var/www/html/
you can access the index.html at
http://localhost:80/html/index.html

I have got problems with nginx http autorisation

I take project from job to home with all of their configuration and with htpasswd.pwd file.
At job all works great, at home i see internal 500 error.
In logs I have got this:
2014/08/03 21:06:53 [crit] 8543#0: *15 open() "/etc/nginx/htpasswd.pwd" failed (13: Permission denied), client: 127.0.0.1, server: mylocal.dev, request: "GET / HTTP/1.1", host: "mylocal.dev"
and here is my namei -l result:
root#laptop:/home/root# namei -l /etc/nginx/htpasswd.pwd
f: /etc/nginx/htpasswd.pwd
drwxr-xr-x root root /
drwxr-xr-x root root etc
drw-r--r-- myuser myuser nginx
-rwxr-xr-x myuser myuser htpasswd.pwd
what i must to do?
Set chmod of htpasswd.pwd to 0755, if this doesn't work set it to 0777.

Categories