每次重启服务器centos7,打开网站都会出现如下报错,提示是权限问题,不知道是不是httpd的配置问题,httpd是配置自动启动的
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Fatal error: Unknown: Failed opening required '/www/frontend/web/index.php' (include_path='.:/usr/local/php/lib/php') in Unknown on line 0
网站是php7.0+httpd2.4, httpd2.4的根目录在/www/frontend/web/index.php下,整个/www目录都有权限,包括/www内部文件也都是777权限都不行。
drwxrwxrwx. 9 root root 4096 Jan 11 23:17 www
只有先
/usr/sbin/httpd -k stop
然后
/usr/sbin/httpd -k start
就可以正常显示,如果是直接使用
/usr/sbin/httpd -k restart
也是不行的。所以操作都在root账户下操作,不知道是为什么?apache运行的权限问题吗?

httpd.conf中运行用户为apache
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache
/usr/sbin/httpd权限
[root@localhost www]# ls -al /usr/sbin/httpd
-rwxrwxrwx. 1 root root 507032 Nov 15 02:05 /usr/sbin/httpd
修改/usr/sbin/httpd重启服务器还是不行
[root@localhost ~]# ls -al /usr/sbin/httpd
-rwxrwxrwx. 1 apache apache 507032 Nov 15 02:05 /usr/sbin/httpd
开机自动启动配置文件:
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
考虑到可能是开机自动启动的权限问题?恳请各位帮忙解答!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
用排除法
先用php自带web Server测试一下,如果正常,那就说明是apache问题。如果不正常,说明是php代码本身有问题
PHP内置的Web Server的使用
getenforce 查看是否因为selinux启动导致的问题,若开启/etc/selinux/config 将selinux修改为disabled,重启服务器。