换了台机器后, Wordpress 更新软件, 直接跳到一个页面让我输 ftp 账号和口令. 然而我并没有搭建这个 ftp.
在 Wordpress 的根目录下 wp-config.php 设置参数如下:
define('FS_METHOD', 'direct');
这个配置告知系统更新就直接通过文件系统, 不再尝试 ftp.
再次尝试升级, 仍然失败.
不过这一次升级失败不再自动跳转到 ftp 登录页面, 而是内容如下:
Downloading update from https://downloads.wordpress.org/release/wordpress....zip…
Unpacking the update…
Warning: copy(/some-prefix/wp-admin/includes/update-core.php): failed to open stream: Permission denied in /some-prefix/wp-admin/includes/class-wp-filesystem-direct.php on line 257 The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.: wp-admin/includes/update-core.php
Installation Failed
查看 audit.log , 可以看到错误信息如下:
# cat /var/log/audit/audit.log | grep denied type=AVC msg=audit(1449669599.587:22782004): avc: denied { write } for pid=xxxx comm="php-fpm" name="update-core.php" dev="dm-1" ino=158226959 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=file
其实就是很简单的权限问题, 如之前提到过的, 解决也很简单.
# cat /var/log/audit/audit.log | grep denied | grep php-fpm | audit2allow -M my-php-fpm ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i my-php-fpm.pp # semodule -i my-php-fpm.pp
执行如上命令即可通过.