我使用命令安装了wordpress 3.5到CentOS 6.3:
yum install wordpress
并启动httpd。 现在我可以在apache日志中看到以下错误:
PHP致命错误:require_once():无法打开所需的'/usr/share/wordpress/wp-includes/class-simplepie.php'(include_path ='。:/ usr / share / pear:/ usr / share / php')在第4行/usr/share/wordpress/wp-includes/class-feed.php上,引用者: http ://www.mycompany.com/wp-admin/
我想这是因为SELinux:
ls -Z /usr/share/wordpress/wp-includes/class-simplepie.php lrwxrwxrwx. root root system_u:object_r:usr_t:s0 class-simplepie.php -> /usr/share/php/php-simplepie ls -Z /usr/share/php/php-simplepie -rw-r--r--. root root unconfined_u:object_r:user_home_t:s0 autoloader.php drwxr-xr-x. root root unconfined_u:object_r:user_home_t:s0 SimplePie -rw-r--r--. root root unconfined_u:object_r:user_home_t:s0 SimplePie.php
我想知道是否有办法让它工作,而不禁用SELinux?
它看起来像你的文件有错误的SELinux安全上下文。 当我安装php-simplepie包(它看起来来自EPEL)并检查这些文件时,它们都具有usr_ttypes,而不是user_home_t 。
尝试修复安全标签:
restorecon -r -v /usr/share/php/php-simplepie
如果你想validation它是SElinux使用setenforce 0来closuresSE linux,或者检查audit.log。 我认为这是在/ var / log / audit / audit / log中,但我不是100%确定的。 一旦你确定它是SELinu,你可以重新打开SElinux。
如果是SElinux,那么要做的就是使用semanage设置selinux策略,以便PHP内容所在的目录为httpd_sys_rw_content_t
semanage fcontext -a -t httpd_sys_rw_content_t </path/to/php/dir>
然后使用restorecon将这个策略应用到目录及其子文件/目录中:
restorecon -R </path/to/php/dir>
如果没有安装semanage/restorecon ,请安装policycoreutils-python软件包。
顺便说一句,如果你想查看默认的文件上下文中的策略,你可以做到这一点:
semanage fcontext -l
但是它可能不是SELinux。 我相信在大多数redhat发行版中,apache并不会遵循符号链接(尽pipe我错误地指出了一些关于不符合链接的错误,所以您可能需要添加:
Options FollowSymLinks
到Apacheconfiguration并重新启动Apache。
当然,它可能既是selinux,也不是符号链接。
这是我为开发人员创build的一个小脚本脚本。 这种方式每次推出WordPress,他们不必记住所有的事情。 你的文件结构几乎肯定有所不同,所以需要修改一下。 请随时提出改进意见。 SELinux不是我的专业,但我正在学习它。
#!/bin/sh # License: Public Domain # satisfies SELinux context requirements for a WordPress site # To operate properly on CentOS, etc. #Figure out what directory to apply this to and strip any trailing / if [ -d $1 ]; then site=${1%/} else site=`pwd` fi #Check to make sure the setting of $site is sane and fail if not if [ ! -d $site/httpdocs/wp-content ]; then echo "ERROR: This does not appear to be an appropriate directory." echo ${site} echo "Please specify directory for the site like /var/www/html/myssite as the only argument" exit 1 fi #For visual appeal mostly content=$site/httpdocs/wp-content #Setup the contexts chcon -R -v -t public_content_rw_t $content/plugins/ $content/themes/ $content/uploads/ $site/logs/ semanage fcontext -a -t httpd_sys_rw_content_t $site/httpdocs/ semanage fcontext -a -t httpd_sys_rw_content_t $site/httpsdocs/ semanage fcontext -a -t httpd_sys_rw_content_t $site/logs/ #Apply the contexts restorecon -R $site/logs/ restorecon -R $site/httpdocs/ restorecon -R $site/httpsdocs/