Nginx + php fastcgi unable to open file, permission denied - php

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"

Related

reload `procmgr` in container?

So I have a docker container build with buildpack that runs the following command under PID 1
procmgr /layers/paketo-buildpacks_php-web/php-web/procs.yml
is it possible to reload the configs passed into procmgr somehow?
🐳 [DEV] backend-v1-7476cc6cfd-l68p2 app #
ps aufx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
cnb 30 1.0 0.0 18648 3444 pts/0 Ss 03:22 0:00 bash
cnb 77 0.0 0.0 34412 2944 pts/0 R+ 03:22 0:00 \_ ps aufx
cnb 1 0.0 0.1 1013616 4096 ? Ssl 03:20 0:00 procmgr /layers/paketo-buildpacks_php-web/php-web/procs.yml
cnb 24 0.0 0.7 323596 31260 ? Ss 03:20 0:00 php-fpm: master process (/layers/paketo-buildpacks_php-web/php-web/etc/php-fpm.conf)
cnb 28 0.3 0.6 330252 24112 ? S 03:20 0:00 \_ php-fpm: pool www
cnb 29 0.1 0.6 330016 23900 ? S 03:20 0:00 \_ php-fpm: pool www
cnb 25 0.0 0.1 25132 5648 ? S 03:20 0:00 nginx: master process nginx -p /workspace/app -c /workspace/app/nginx.conf
cnb 26 0.0 0.0 25132 1988 ? S 03:20 0:00 \_ nginx: worker process
cnb 27 0.0 0.0 25132 1988 ? S 03:20 0:00 \_ nginx: worker process
🐳 [DEV] backend-v1-7476cc6cfd-l68p2 app #
cat /layers/paketo-buildpacks_php-web/php-web/procs.yml
processes:
nginx:
command: nginx
args:
- -p
- /workspace/app
- -c
- /workspace/app/nginx.conf
php-fpm:
command: php-fpm
args:
- -p
- /layers/paketo-buildpacks_php-web/php-web
- -y
- /layers/paketo-buildpacks_php-web/php-web/etc/php-fpm.conf
- -c
- /layers/paketo-buildpacks_php-web/php-web/etc
At the time of writing this, no. The procmgr cli that is used here is very basic.
https://github.com/paketo-buildpacks/php-web/blob/main/cmd/procmgr/main.go
It loads the processes information listed in procs.yml, starts those processes, redirects all STDOUT/STDERR, and watches for a process to exit. If one process exits, then they all exit. There's no reload capability.
If you need to reload the information in procs.yml, you'll need to reload your container.

White Site after Ubuntu and PHP Update

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.

Supervisor is not started into my docker container (Laravel project)

Supervisor is not started into my container and i am not able to run my php artisan queue:work command for my laravel project.
Extract from my Dockerfile
# Add worker to supervisor config file
COPY laravel-worker.conf /etc/supervisor/conf.d/
CMD ["/usr/bin/supervisord"]
Here is the laravel-worker.conf:
[program:laravel-worker]
command=php /var/www/test/current/artisan queue:work --tries=3
user=myuser
process_name=%(program_name)s_%(process_num)d
directory=/var/www/test/current
stdout_logfile=/tmp/supervisord.log
redirect_stderr=true
numprocs=1
autostart=true
autorestart=true
When i go into the container, the supervisor service is not started:
root#e7227ef40f63:/# service supervisor status
supervisord is not running.
And process are following:
root#e7227ef40f63:/# ps -aux | grep supervisor
root 1 0.0 0.0 4328 652 ? Ss 18:21 0:00 /bin/sh -c service ssh restart && service apache2 restart && service cron start && bash /usr/bin/supervisord
root 365 0.0 0.0 55808 10632 ? Ss 18:25 0:00 /usr/bin/python /usr/bin/supervisord
root 380 0.0 0.0 11120 712 ? S+ 18:27 0:00 grep supervisor
UPDATE
I edited my DockerFile and put this line:
ENTRYPOINT service ssh restart && service apache2 restart && service cron start && /usr/bin/supervisord && bash
The service is now well started when the container starts :
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.1 0.0 4328 652 ? Ss 05:20 0:00 /bin/sh -c service ssh restart && service apache2 restart && service cron start && /usr/bin/supervisord && bash
root 25 0.0 0.0 55176 1140 ? Ss 05:20 0:00 /usr/sbin/sshd
root 43 0.1 0.0 406408 25504 ? Ss 05:20 0:00 /usr/sbin/apache2 -k start
www-data 46 0.0 0.0 406440 8416 ? S 05:20 0:00 /usr/sbin/apache2 -k start
www-data 47 0.0 0.0 406440 8416 ? S 05:20 0:00 /usr/sbin/apache2 -k start
www-data 48 0.0 0.0 406440 8416 ? S 05:20 0:00 /usr/sbin/apache2 -k start
www-data 49 0.0 0.0 406440 8416 ? S 05:20 0:00 /usr/sbin/apache2 -k start
www-data 50 0.0 0.0 406440 8416 ? S 05:20 0:00 /usr/sbin/apache2 -k start
root 59 0.0 0.0 17484 636 ? Ss 05:20 0:00 /usr/sbin/cron
root 63 0.2 0.0 56012 10788 ? Ss 05:20 0:00 /usr/bin/python /usr/bin/supervisord
root 64 0.0 0.0 20032 1280 ? S 05:20 0:00 bash
root 89 0.1 0.0 20240 1996 ? Ss 05:20 0:00 bash
root 112 0.0 0.0 17492 1168 ? R+ 05:21 0:00 ps -aux
But it seams that supervisor doesn't start my config file because i don't see the 8 processes that should be run..
This is the bad part:
&& bash /usr/bin/supervisord
supervisord is not a bash script. Execute it as is: && /usr/bin/supervisord.
However, I recommend you to completely avoid using service in a container. In general, running more than one process into a container is considered an antipattern, but if you really need it, better only use supervisor . Create a .conf file for each process (cron, sshd, etc) and only run supervosord as is in your CMD.

Generate a file by PHP

I want to generate a file by batch.php, which is linked to the button in this page:
<?php
echo "Hello world!";
'cat 123 > uploads/cat.txt';
echo "Bye world!";
?>
Clicking on the button does launch batch.php, however, cat.txt is NOT generated on the server side.
Does anyone know how to fix this? Maybe I need to setup some permission for the folder?
Edit 1:
ps aux|grep -E 'apache|www-data|http|php' returns:
root 12269 0.0 2.1 278256 10796 ? Ss Aug02 3:38 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 12301 0.0 0.8 97728 4044 ? S Aug02 3:27 nginx: worker process
www-data 12302 0.0 0.8 98104 4296 ? S Aug02 3:54 nginx: worker process
www-data 12303 0.0 0.9 97940 4520 ? S Aug02 3:46 nginx: worker process
www-data 12304 0.0 0.9 98132 4544 ? S Aug02 3:47 nginx: worker process
timur 14888 0.0 0.1 11712 932 pts/0 S+ 15:04 0:00 grep --color=auto -E apache|www-data|http|php
www-data 18748 0.0 8.7 298196 43668 ? S Sep07 0:12 php-fpm: pool www
www-data 18749 0.0 6.4 286660 32432 ? S Sep07 0:11 php-fpm: pool www
www-data 21100 0.0 8.3 296204 42048 ? S Sep05 1:02 php-fpm: pool www
ls -l returns:
total 20
-rw-r--r-- 1 root root 84 Sep 12 08:33 batch.php
-rw-r--r-- 1 timur timur 5120 Sep 12 09:00 generateFile.exe
-rw-rw-r-- 1 timur timur 138 Sep 12 08:28 index.html
drwxrwxrwx 2 timur timur 4096 Sep 12 15:03 uploads
I granted 777 to uploads, and I tried all the possible owner names and owner groups (ie, timur:timur, www-data:www-data and root:root), but none of them works...
The key is to write exec('cat 123 > uploads/cat.txt') or shell_exec('cat 123 > uploads/cat.txt') instead of 'cat 123 > uploads/cat.txt'.
Then, although drwxrwxrwx 2 timur timur 4096 Sep 12 15:03 uploads works, assigning 755 and www-data:www-data (reserved to PhP) to uploads is more correct.

php sessions saved in ramdisk

I'm trying to save my php session on ramdisk. I have a permission problem but i can't see what where it's the problem.
I have the ramdisk:
/dev/ram0 407M 2.4M 404M 1% /var/lib/php/session/ramd
I have the permissions:
drwxrwx---. 3 root apache 1024 Mar 24 01:53 ramd
My error:
Warning: session_start(): open(/var/lib/php/session/ramd/sess_b0ko6hl3p6ojj2ot3qfqvm9km1, O_RDWR) failed: Permission denied (13) in /var/www/html/index.php on line 3 Warning: Unknown: open(/var/lib/php/session/ramd/sess_b0ko6hl3p6ojj2ot3qfqvm9km1, O_RDWR) failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session/ramd) in Unknown on line 0
In php.ini, session.save_path variable it's set to "/var/lib/php/session"
In my script i set session.save_path to "var/lib/php/session/ramd"
If i umont the ramdisk that i created, i can save my sessions in /rand folder. It i mount.. i can't. I tried also chmod root:root / apache:apache with chmod 0777 1777. now it's 0770.
I using: CentOS 6.4, PHP 5.3.3, Apache/2.2.15
Can anybody help me with this problem??
LE:
[root#localhost ~]# ps aux | grep apache
apache 2355 0.0 0.4 394868 7840 ? S 01:53 0:00 /usr/sbin/httpd
apache 2356 0.0 0.4 394876 7844 ? S 01:53 0:00 /usr/sbin/httpd
apache 2357 0.0 0.4 394876 7824 ? S 01:53 0:00 /usr/sbin/httpd
apache 2358 0.0 0.4 394876 7816 ? S 01:53 0:00 /usr/sbin/httpd
apache 2360 0.0 0.4 394876 7900 ? S 01:53 0:00 /usr/sbin/httpd
apache 2361 0.0 0.4 394876 7800 ? S 01:53 0:00 /usr/sbin/httpd
apache 2362 0.0 0.4 394876 7844 ? S 01:53 0:00 /usr/sbin/httpd
apache 2363 0.0 0.4 394868 7716 ? S 01:53 0:00 /usr/sbin/httpd
root 3119 0.0 0.0 103248 868 pts/0 S+ 02:52 0:00 grep apache
[root#localhost ~]# ps aux | grep php
root 3132 0.0 0.0 103244 868 pts/0 S+ 02:54 0:00 grep php
Execute the following to see if SELinux is in enforcing mode:
# sestatus
If so, you may want to try disabling SELinux by running the following as root (or with sudo):
# setenforce 0
This will make SELinux stop enforcing any policies. If this solves the issue, you will have to either leave SELinux off or augment the policy to allow this new path to work out correctly. If it does get to that point, reference https://serverfault.com/a/323528/165777 for some information on how to perform that step!
Also, if that didn't make an impact and/or you want to re-enable SELinux, execute:
# setenforce 1

Categories