首次启动WordPress时出现500服务器错误求助
排查LEMP环境下WordPress初始化时500内部服务器错误的步骤
1. 查看错误日志获取具体原因
Nginx和PHP-FPM的错误日志会明确给出500错误的触发原因,执行以下命令查看最新日志:
tail -n 20 /var/log/nginx/error.log tail -n 20 /var/log/php8.1-fpm.log
(Ubuntu 22.04默认搭载PHP 8.1,若你使用其他版本,替换命令中的php8.1)
2. 验证Nginx站点配置合法性
检查你的Nginx站点配置文件(通常在/etc/nginx/sites-available/目录下),确保WordPress相关的location规则配置正确,示例配置如下:
location /wordpress { try_files $uri $uri/ /wordpress/index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
执行nginx -t验证配置语法是否合法,若有错误会直接提示修复方向。
3. 修正WordPress文件及目录权限
虽然你已设置charch文件夹权限为www-data:www-data,但WordPress内部文件权限也需符合规范:
- 所有文件权限设为
644 - 所有目录权限设为
755 - wp-content/uploads目录需设为
775(保证PHP进程可写入)
执行以下命令批量设置:
sudo find /path/to/charch/wordpress -type f -exec chmod 644 {} \; sudo find /path/to/charch/wordpress -type d -exec chmod 755 {} \; sudo chmod 775 /path/to/charch/wordpress/wp-content/uploads
4. 确认PHP-FPM服务状态与权限
确保PHP-FPM服务正常运行:
sudo systemctl status php8.1-fpm
若服务未启动,执行以下命令启动并设置开机自启:
sudo systemctl start php8.1-fpm sudo systemctl enable php8.1-fpm
同时检查PHP-FPM套接字文件权限:
ls -l /run/php/php8.1-fpm.sock
该文件权限需为www-data:www-data,否则Nginx无法与PHP-FPM通信。
5. 验证数据库连接配置
若已生成wp-config.php文件,检查其中的数据库参数是否与你创建的数据库信息一致:
define( 'DB_NAME', '你的数据库名' ); define( 'DB_USER', '你的数据库用户' ); define( 'DB_PASSWORD', '你的数据库密码' ); define( 'DB_HOST', 'localhost' );
若还未生成wp-config.php,确认你已按照文档要求创建了WordPress对应的数据库和授权用户。
6. 检查PHP必要扩展
WordPress依赖mysqli、json、curl等扩展,执行以下命令查看已安装的PHP扩展:
php -m
若缺失必要扩展,安装对应包后重启PHP-FPM:
sudo apt install php8.1-mysqli php8.1-json php8.1-curl sudo systemctl restart php8.1-fpm
内容的提问来源于stack exchange,提问作者Daniil
相关产品推荐
相关产品推荐

