nginx permission denied error on alpine drupal 8 docker image - php

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?

Related

Where can I find php-fpm.log and php-fpm.conf on my server?

I think I am having problems with the max children limit for php-fpm. I am trying to find something in the logs. Where can I find php-fpm.log on my server? Running phpinfo() shows this:
I cannot find anything related to php-fpm in /var/log/.
I am also trying to find the php-fpm.conf that is mentioned at https://www.php.net/manual/en/install.fpm.configuration.php. Thank you.
UPDATE 1: I found at https://github.com/rlerdorf/php7dev/issues/48 that it asks to edit /usr/local/etc/php-fpm.d/www.conf. In my case, I cannot find that file:
root#jai [/usr/local/etc]# pwd
/usr/local/etc
root#jai [/usr/local/etc]# ls -al
total 8
drwxr-xr-x. 2 root root 4096 Sep 23 2011 ./
drwxr-xr-x. 15 root root 4096 Apr 7 15:02 ../
Do I need to create it at /usr/local/etc/php-fpm.d/www.conf?
UPDATE 2: I see I have a folder called ApachePHPFPM but the file inside (default_accounts_to_fpm) is empty:
root#jai [/var/cpanel/ApachePHPFPM]# pwd
/var/cpanel/ApachePHPFPM
root#jai [/var/cpanel/ApachePHPFPM]# ls -al
total 16
drwxr-xr-x 2 root root 4096 Mar 26 04:44 ./
drwx--x--x 108 root root 12288 Apr 17 13:44 ../
-rw-r--r-- 1 root root 0 Mar 26 04:44 default_accounts_to_fpm
root#jai [/var/cpanel/ApachePHPFPM]#
UPDATE 3: My server had this file:
/usr/local/cpanel/etc/php-fpm.conf
The file contains this:
; Error log file
; Default Value: /var/log/php-fpm.log
error_log = /usr/local/cpanel/logs/php-fpm/error.log
That means that my error logs for php-fpm are located in this file: /usr/local/cpanel/logs/php-fpm/error.log.
I navigated to /usr/local/cpanel/logs/php-fpm/ but I could not find error.log:
root#jai [/usr/local/cpanel/etc]# cd /usr/local/cpanel/logs/php-fpm/
root#jai [/usr/local/cpanel/logs/php-fpm]# ls -al
total 8
drwx------ 2 root root 4096 Mar 30 2018 ./
drwx--x--x 6 root root 4096 Apr 16 15:24 ../
root#jai [/usr/local/cpanel/logs/php-fpm]#
In /opt/cpanel/ea-php73/root/etc/php-fpm.conf I found this line:
error_log = /opt/cpanel/ea-php73/root/usr/var/log/php-fpm/error.log
I see the error log files there:
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# pwd
/opt/cpanel/ea-php73/root/usr/var/log/php-fpm
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# ls -al
total 151456
drwxrwx--- 2 nobody root 4096 Apr 14 17:36 ./
drwxr-xr-x 3 root root 4096 Mar 26 04:42 ../
-rw------- 1 root root 31536068 Apr 17 17:05 error.log
-rw------- 1 root root 32102325 Mar 29 03:26 error.log-20200329
-rw------- 1 root root 51453659 Apr 5 03:36 error.log-20200405
-rw------- 1 root root 39966549 Apr 12 02:55 error.log-20200412
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]#

CentOS, Nginx: 403 Forbidden in Laravel's folder

I use laravel new test to establish the Laravel project and move all directories into /usr/share/nginx/html/, the default root directory of Nginx.
In order to check if the config of nginx is correct, I simply the config, trun on autoindex, and put index,html into /usr/share/nginx/html/test/public/, the location of index.php of laravel.
defaul.conf of nginx
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html/test;
index index.html index.htm index.php;
location / {
autoindex on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
When I access the index.html by localhost/public/, nginx returns me 403. I copy index.html into a new folder named /usr/share/nginx/html/test/public_b, and try to access the new index.html by localhost/public_b/. Nginx returns me the correct content! It is like a miracle. The stats of my directories as the follows.
$ll /usr/share/html/test
total 432
drwxrwxr-x. 6 nginx nginx 84 Feb 26 15:39 app
-rw-rw-r--. 1 nginx nginx 1686 Feb 26 15:39 artisan
drwxrwxr-x. 3 nginx nginx 34 Feb 26 15:39 bootstrap
-rw-rw-r--. 1 nginx nginx 1512 Feb 26 15:39 composer.json
-rw-rw-r--. 1 nginx nginx 145089 Feb 26 15:39 composer.lock
drwxrwxr-x. 2 nginx nginx 247 Feb 26 15:39 config
drwxrwxr-x. 5 nginx nginx 72 Feb 26 15:39 database
-rwxrwxr-x. 1 nginx nginx 13 Feb 26 17:46 index.html
-rw-rw-r--. 1 nginx nginx 1150 Feb 26 15:39 package.json
-rw-rw-r--. 1 nginx nginx 1040 Feb 26 15:39 phpunit.xml
drwxr-xr-x. 4 root root 116 Feb 26 18:05 public
drwxr-xr-x. 2 root root 24 Feb 26 17:50 public_c
drwxrwxr-x. 5 nginx nginx 45 Feb 26 15:39 resources
drwxrwxr-x. 2 nginx nginx 75 Feb 26 16:50 routes
-rw-rw-r--. 1 nginx nginx 563 Feb 26 15:39 server.php
drwxr-xr-x. 5 nginx nginx 46 Feb 26 15:39 storage
drwxrwxr-x. 4 nginx nginx 83 Feb 26 15:39 tests
drwxrwxr-x. 37 nginx nginx 4096 Feb 26 15:40 vendor
-rw-rw-r--. 1 nginx nginx 549 Feb 26 15:39 webpack.mix.js
-rw-rw-r--. 1 nginx nginx 258941 Feb 26 15:39 yarn.lock
$ ll /usr/share/nginx/html/test/public
total 12
drwxrwxr-x. 2 nginx nginx 21 Feb 26 15:39 css
-rw-rw-r--. 1 nginx nginx 0 Feb 26 15:39 favicon.ico
-rwxr-xr-x. 1 root root 13 Feb 26 17:49 index.html
-rw-rw-r--. 1 nginx nginx 1823 Feb 26 15:39 index.php
drwxrwxr-x. 2 nginx nginx 20 Feb 26 15:39 js
-rw-rw-r--. 1 nginx nginx 24 Feb 26 15:39 robots.txt
$ ll /usr/share/nginx/html/test/public_c/
total 4
-rwxr-xr-x. 1 root root 13 Feb 26 17:50 index.html
I have read a lot of relative questions and pages, but nothing help against this problem. What is wrong in my actions or settings?
Update
Thanks #Adam Kozlowski. I tried chmod 777 public -R and changing owner to both of root and nginx, but the problem was not solved.
I found the problem: SELinux blocked Nginx to access the folders.
$ ls /usr/share/nginx/html/test/ -Z
drwxr-xr-x. root root unconfined_u:object_r:config_home_t:s0 public
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 public_c
Only the files with the tag, httpd_sys_content_t, can be accessed by HTTP.
Command:
chcon -R -t httpd_sys_content_t /usr/share/nginx/html/test
And I also need to add httpd_sys_rw_content_t to /usr/share/nginx/html/test/storage to let Laravel work.
Command:
chcon -R -t httpd_sys_rw_content_t/usr/share/nginx/html/test/storage
Referring Permissions Issue with Laravel on CentOS
Set proper permission for directory, as a root user:
chmod a+rwx directory-name -R

webhook php file work from terminal but not from bitbucket

I'm using bitbucket to host my git repository, the repo holds a test website at the moment, I have created a bitbucket webhook, so when I push to the bitbucket repo, the changes show up as live on the digitalOcean VPS, in other words.. when bitbucket receives a push, it calls the webhook php file, and that php file has a shell script that pulls from github..
the hook file
Hook path : /var/www/html/hook.php
the site folder
Site path : /var/www/html/webhooks/
the hook.php file looks like so
<?php
echo "________PHP_AUTO_PULL________";
$output = shell_exec('git -C ./webhooks/ pull https://userName:password#bitbucket.org/userName/repo.git master');
echo "<pre>$output</pre>";
?>
when I do this in terminal
php hook.php
it does the job normally, and it pulls..
but the problem is, webhooks only shows this reply
________PHP_AUTO_PULL________
indicating that it does no pull, yes I have checked, no pull occured, how to make the hook execute the file normally?
permissions and owners are provided in these listings
listing for /var/www/html/
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 3 16:49 ../
-rwxrwxrwx 1 www-data root 200 Mar 28 09:05 hook.php*
-rw-rw-r-- 1 www-data www-data 20 Mar 3 16:49 info.php
drwxr-xr-x 3 root root 4096 Mar 28 09:03 webhooks/
listing for /var/www/html/webhooks/
drwxr-xr-x 3 root root 4096 Mar 28 09:03 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ../
-rw-r--r-- 1 root root 295 Mar 27 15:13 content.html
drwxr-xr-x 8 root root 4096 Mar 28 09:03 .git/
-rw-r--r-- 1 root root 444 Mar 27 15:13 index.html
-rw-r--r-- 1 root root 963 Mar 27 15:13 menu_1.html
-rw-r--r-- 1 root root 13 Mar 28 09:03 number.txt
my webserver is nginx
any idea why it works from terminal, but bitbucket can't have it to work?
I have managed to solve it, using :
echo shell_exec("/usr/bin/git pull https://userName:password#bitbucket.org/userName/repo.git master 2>&1");
the 2>&1 part was helping me to see errors about permissions of folders, I used
chown -R www-data .git/
and it's working fine.

php 7.0 fpm separate error logs for pools not working

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

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.

Categories