升级php56w至5.6.35后WordPress文件权限异常求助
Hey Jordan, let's work through this permission problem you're facing after upgrading PHP. This is super common when switching PHP versions with FastCGI setups, since the user/group running your PHP process might have changed or file ownership got messed up during the upgrade. Here's what to do step by step:
1. Confirm the User/Group Running PHP-FPM
First, we need to make sure we know exactly which user your FastCGI (php-fpm) process is running as. On CentOS 7, it's usually apache, but let's verify for sure:
ps aux | grep php-fpm
Look at the user column next to the php-fpm worker processes—this is the user we'll need to set ownership to for your WordPress files.
2. Fix WordPress File/Directory Ownership
Once you have the correct user/group (we'll use apache:apache as the default example), update the ownership of your entire WordPress directory:
chown -R apache:apache /path/to/your/wordpress/root
Replace /path/to/your/wordpress/root with your actual WordPress install path (like /var/www/html/wordpress).
3. Set Secure, Functional File/Directory Permissions
Next, apply standard WordPress permissions to balance security and functionality:
- Directories need
755(read/write/execute for owner, read/execute for others) - Files need
644(read/write for owner, read for others)
Run these two commands:
# Fix directory permissions find /path/to/your/wordpress -type d -exec chmod 755 {} \; # Fix file permissions find /path/to/your/wordpress -type f -exec chmod 644 {} \;
4. Double-Check Your wp-config.php Setup
You already added define('FS_METHOD', 'direct');, but let's confirm it's set up correctly:
- Make sure this line is placed before the final line
require_once(ABSPATH . 'wp-settings.php');inwp-config.php - Check for duplicate
FS_METHODdefinitions later in the file that might override your setting
5. Verify PHP-FPM Pool Configuration
PHP upgrades sometimes reset the pool user/group settings. Open your php-fpm pool config (usually /etc/php-fpm.d/www.conf on CentOS 7) and confirm these lines are set to the user we identified earlier:
user = apache group = apache
After making any changes, restart php-fpm and Apache to apply the updates:
systemctl restart php-fpm systemctl restart httpd
6. Handle SELinux Restrictions (CentOS 7 Specific)
CentOS 7 uses SELinux by default, which can block Apache from writing to WordPress directories even if file permissions look correct.
- First, test if SELinux is the issue by temporarily disabling it:
If uploading files/updating works now, we'll set the correct SELinux context instead of keeping it disabled:setenforce 0
This gives Apache the necessary write access to thechcon -R -t httpd_sys_rw_content_t /path/to/your/wordpress/wp-contentwp-contentdirectory (where uploads, plugins, and core updates are stored).
After working through these steps, your WordPress should be able to handle file uploads, plugin updates, and core updates without asking for FTP credentials. Let me know if any step gives you trouble!
内容的提问来源于stack exchange,提问作者Jordan

