Home » Php » Warning failed to open stream permission denied fatal error require_once PHP + NginX + RHEL in VMware

Warning failed to open stream permission denied fatal error require_once PHP + NginX + RHEL in VMware

Posted by: admin October 26, 2017 Leave a comment

Questions:

Context: Set up NginX with php.fpm on a virtual RHEL 7.3. I’m able to open http://hostname/webcon/index.php if it contains plain html or simple php. However, when I use require_once (I’ve checked the path), I’m getting the below error.

Warning: require_once(/mnt/data/service/common/dbconfig.php): failed to open stream: Permission denied in /mnt/data/service/webcon/user.php on line 7

Fatal error: require_once(): Failed opening required '/mnt/data/service/common/dbconfig.php' (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/data/service/webcon/user.php on line 7

Here is the snippet of my www.conf in /php-fpm.d

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

Here is the snippet of my nginx.conf in /etc/nginx

user  apache;
worker_processes  auto;

error_log  /mnt/data/service/caldav/logs/error.log debug;
pid        /var/run/nginx.pid;

ps -aux | grep nginx shows:

root      43982  0.0  0.0  58756  1064 ?        Ss   15:07   0:00 nginx: master process /usr/sbin/nginx
apache    43983  0.0  0.0  61340  2624 ?        S    15:07   0:00 nginx: worker process
root      44199  0.0  0.0 112648   960 pts/1    S+   15:23   0:00 grep --color=auto nginx

I have also assigned chmod 777 to all the parents/sub-folders required. All of them are owned by root/root for now. Not sure what else I need to do. I have tried in vain all the answers/suggestions I’ve found while Googling..

Edit 1:

Tried changing user:group to www-data. Get the error below.

Oct 26 15:32:25 nixs systemd[1]: Starting The PHP FastCGI Process Manager...
Oct 26 15:32:25 nixs php-fpm[44320]: [26-Oct-2017 15:32:25] ERROR: [pool www] cannot get uid for user 'www-data'
Oct 26 15:32:25 nixs php-fpm[44320]: [26-Oct-2017 15:32:25] ERROR: FPM initialization failed
Oct 26 15:32:25 nixs systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Oct 26 15:32:25 nixs systemd[1]: Failed to start The PHP FastCGI Process Manager.
Oct 26 15:32:25 nixs systemd[1]: Unit php-fpm.service entered failed state.
Oct 26 15:32:25 nixs systemd[1]: php-fpm.service failed.
Answers:

you did CHMOD 777 or CHMOD -R 777 , if youd have executed the first one I suggest you to do the second one.

If chmod is not working, maybe you need to do a CHOWN to assign the user in your your folder and subfolder like this : CHOWN -R apache:apache /mnt/data/...