CakePHP 权限错误
CakePHP permissions error
这似乎是重复的,但我已经阅读了类似的问题并尝试了他们的建议,但没有奏效。
当我导航到我的 CakePHP 网站时,我收到以下错误
Warning (2): mkdir(): Permission denied
[CORE/src/Cache/Engine/FileEngine.php, line 417]
Warning: file_put_contents(/var/www/html/my-application/logs/error.log)
[function.file-put-contents]: failed to open stream: Permission denied
in
/var/www/html/my-application/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php
on line 134
Warning (512): /var/www/html/my-application/tmp/cache/persistent/ is not
writable [CORE/src/Cache/Engine/FileEngine.php, line 425]
Warning (2):
file_put_contents(/var/www/html/my-application/logs/error.log)
[function.file-put-contents]: failed to open stream: Permission denied
[CORE/src/Log/Engine/FileLog.php, line 134]
Warning: file_put_contents(/var/www/html/my-application/logs/error.log)
[function.file-put-contents]: failed to open stream: Permission denied
in
/var/www/html/my-application/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php
on line 134
我确定 PHP 可以访问所有必要的文件。
PHP 作为 apache 用户在 apache 组中运行。证据:
[ec2-user@cv-stg01 my-application]$ ps -efl | grep apache
5 S apache 21863 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21864 21861 0 80 0 - 123971 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21865 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21867 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21868 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21869 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21870 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21881 21861 0 80 0 - 123485 SYSC_s 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21882 21861 0 80 0 - 123485 SYSC_s 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21883 21861 0 80 0 - 125444 ep_pol 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
0 S ec2-user 21934 21785 0 80 0 - 28161 pipe_w 03:20 pts/0 00:00:00 grep --color=auto apache
相关目录归 apache:apache 所有,权限设置为 777:
[ec2-user@cv-stg01 my-application]$ ls -l
total 132
drwxrwxr-x. 2 apache apache 47 May 12 21:16 bin
-rw-rw-r--. 1 apache apache 1128 May 12 21:16 composer.json
-rw-rw-r--. 1 apache apache 93002 May 12 21:16 composer.lock
drwxrwxr-x. 3 apache apache 4096 May 12 21:19 config
-rw-rw-r--. 1 apache apache 648 May 12 21:16 index.php
drwxrwxrwx. 2 apache apache 34 May 13 03:10 logs
-rw-rw-r--. 1 apache apache 1139 May 12 21:16 phpunit.xml.dist
drwxrwxr-x. 2 apache apache 18 May 12 21:16 plugins
-rw-rw-r--. 1 apache apache 980 May 12 21:16 README.md
drwxrwxr-x. 9 apache apache 4096 May 12 21:16 src
drwxrwxrwx. 4 apache apache 55 May 12 21:16 tests
drwxrwxrwx. 2 apache apache 6 May 13 03:17 tmp
drwxrwxr-x. 28 apache apache 4096 May 12 21:16 vendor
drwxrwxr-x. 9 apache apache 4096 May 12 21:16 webroot
tmp/ 中的子目录也有正确的权限:
[ec2-user@cv-stg01 tmp]$ ls -l
total 0
drwxrwxrwx. 5 apache apache 48 May 12 21:16 cache
drwxrwxrwx. 2 apache apache 18 May 12 21:16 sessions
drwxrwxrwx. 2 apache apache 18 May 12 21:16 tests
我也尝试重新应用权限,以防万一,使用
sudo chown -R apache:apache /var/www/html/my-application
sudo chmod -R 777 /var/www/html/my-application/tmp
sudo chmod -R 777 /var/www/html/my-application/logs
sudo chmod -R 777 /var/www/html/my-application/tests
我什至以 apache 身份登录并自己编辑文件,没有任何问题
sudo su -s /bin/bash apache
vi /var/www/html/my-applciation/logs/error.log
我现在真的很难弄清楚问题出在哪里。
我们有 SELinux installed/enabled,所以这可能会导致问题?
将不胜感激。
谢谢,
YM
所有人都知道,将权限设置为777
不是一个好的做法。我在 CakePHP installation doc 中找到了这个有用的提示,希望这会有所帮助 (;
setfacl -R -m u:apache:rwx app/tmp
setfacl -R -d -m u:apache:rwx app/tmp
试试这个:
chown -R apache.apache /path/to/html/
chmod -R 777 /path/to/html/
然后重启httpd服务:
service httpd restart
问题出在 SELinux 上。使用以下命令已解决:
chcon -R system_u:object_r:var_lib_t:s0 tmp
chcon -R system_u:object_r:var_lib_t:s0 logs
chcon system_u:object_r:httpd_var_lib_t:s0 logs/*
chcon system_u:object_r:httpd_var_lib_t:s0 tmp/debug_kit.sqlite
chcon system_u:object_r:var_lib_t:s0 tests
chmod -R o-w tmp logs tests
这似乎是重复的,但我已经阅读了类似的问题并尝试了他们的建议,但没有奏效。
当我导航到我的 CakePHP 网站时,我收到以下错误
Warning (2): mkdir(): Permission denied [CORE/src/Cache/Engine/FileEngine.php, line 417]
Warning: file_put_contents(/var/www/html/my-application/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/my-application/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 134
Warning (512): /var/www/html/my-application/tmp/cache/persistent/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 425]
Warning (2): file_put_contents(/var/www/html/my-application/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied [CORE/src/Log/Engine/FileLog.php, line 134]
Warning: file_put_contents(/var/www/html/my-application/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/my-application/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 134
我确定 PHP 可以访问所有必要的文件。
PHP 作为 apache 用户在 apache 组中运行。证据:
[ec2-user@cv-stg01 my-application]$ ps -efl | grep apache
5 S apache 21863 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21864 21861 0 80 0 - 123971 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21865 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21867 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21868 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21869 21861 0 80 0 - 123485 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21870 21861 0 80 0 - 124037 SYSC_s 03:06 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21881 21861 0 80 0 - 123485 SYSC_s 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21882 21861 0 80 0 - 123485 SYSC_s 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
5 S apache 21883 21861 0 80 0 - 125444 ep_pol 03:09 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
0 S ec2-user 21934 21785 0 80 0 - 28161 pipe_w 03:20 pts/0 00:00:00 grep --color=auto apache
相关目录归 apache:apache 所有,权限设置为 777:
[ec2-user@cv-stg01 my-application]$ ls -l
total 132
drwxrwxr-x. 2 apache apache 47 May 12 21:16 bin
-rw-rw-r--. 1 apache apache 1128 May 12 21:16 composer.json
-rw-rw-r--. 1 apache apache 93002 May 12 21:16 composer.lock
drwxrwxr-x. 3 apache apache 4096 May 12 21:19 config
-rw-rw-r--. 1 apache apache 648 May 12 21:16 index.php
drwxrwxrwx. 2 apache apache 34 May 13 03:10 logs
-rw-rw-r--. 1 apache apache 1139 May 12 21:16 phpunit.xml.dist
drwxrwxr-x. 2 apache apache 18 May 12 21:16 plugins
-rw-rw-r--. 1 apache apache 980 May 12 21:16 README.md
drwxrwxr-x. 9 apache apache 4096 May 12 21:16 src
drwxrwxrwx. 4 apache apache 55 May 12 21:16 tests
drwxrwxrwx. 2 apache apache 6 May 13 03:17 tmp
drwxrwxr-x. 28 apache apache 4096 May 12 21:16 vendor
drwxrwxr-x. 9 apache apache 4096 May 12 21:16 webroot
tmp/ 中的子目录也有正确的权限:
[ec2-user@cv-stg01 tmp]$ ls -l
total 0
drwxrwxrwx. 5 apache apache 48 May 12 21:16 cache
drwxrwxrwx. 2 apache apache 18 May 12 21:16 sessions
drwxrwxrwx. 2 apache apache 18 May 12 21:16 tests
我也尝试重新应用权限,以防万一,使用
sudo chown -R apache:apache /var/www/html/my-application
sudo chmod -R 777 /var/www/html/my-application/tmp
sudo chmod -R 777 /var/www/html/my-application/logs
sudo chmod -R 777 /var/www/html/my-application/tests
我什至以 apache 身份登录并自己编辑文件,没有任何问题
sudo su -s /bin/bash apache
vi /var/www/html/my-applciation/logs/error.log
我现在真的很难弄清楚问题出在哪里。
我们有 SELinux installed/enabled,所以这可能会导致问题?
将不胜感激。
谢谢,
YM
所有人都知道,将权限设置为777
不是一个好的做法。我在 CakePHP installation doc 中找到了这个有用的提示,希望这会有所帮助 (;
setfacl -R -m u:apache:rwx app/tmp
setfacl -R -d -m u:apache:rwx app/tmp
试试这个:
chown -R apache.apache /path/to/html/
chmod -R 777 /path/to/html/
然后重启httpd服务:
service httpd restart
问题出在 SELinux 上。使用以下命令已解决:
chcon -R system_u:object_r:var_lib_t:s0 tmp
chcon -R system_u:object_r:var_lib_t:s0 logs
chcon system_u:object_r:httpd_var_lib_t:s0 logs/*
chcon system_u:object_r:httpd_var_lib_t:s0 tmp/debug_kit.sqlite
chcon system_u:object_r:var_lib_t:s0 tests
chmod -R o-w tmp logs tests