没有不值得去解决的问题,也没有不值得去学习的技术!

Resolving HTTP ERROR 500 When Installing WordPress With Nginx on CentOS 7.6 64-bit

Open the URL: http://www.aaaacn.net/wp-admin/install.php, and an error occurs: HTTP ERROR 500

1. Open the URL: http://www.aaaacn.net/wp-admin/install.php, and an error occurs: HTTP ERROR 500, as shown in Figure 1

Open the URL: http://www.aaaacn.net/wp-admin/install.php, and an error occurs: HTTP ERROR 500
Figure 1

2. Open the URL: http://www.aaaacn.net/phpinfo.php, and it runs normally, as shown in Figure 2

Open the URL: http://www.aaaacn.net/phpinfo.php, and it runs normally
Figure 2

3. View the Virtualhost conf: /usr/local/nginx/conf/vhost/www.aaaacn.net.conf

Nginx

	server {
	  listen 80;
	  server_name www.aaaacn.net aaaacn.net;
	  access_log /data/wwwlogs/www.aaaacn.net_nginx.log combined;
	  index index.html index.htm index.php;
	  root /data/wwwroot/www.aaaacn.net;
	  if ($host != www.aaaacn.net) {  return 301 $scheme://www.aaaacn.net$request_uri;  }
	  include /usr/local/nginx/conf/rewrite/wordpress.conf;
	  #error_page 404 /404.html;
	  #error_page 502 /502.html;
	  
	  location ~ [^/]\.php(/|$) {
		#fastcgi_pass remote_php_ip:9000;
		fastcgi_pass unix:/dev/shm/php-cgi.sock;
		fastcgi_index index.php;
		include fastcgi.conf;
	  }

	  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
		expires 30d;
		access_log off;
	  }
	  location ~ .*\.(js|css)?$ {
		expires 7d;
		access_log off;
	  }
	  location ~ /\.ht {
		deny all;
	  }
	}

4. View the Rewrite rule: /usr/local/nginx/conf/rewrite/wordpress.conf

Nginx

	location / {
	  try_files $uri $uri/ /index.php?$args;
	}
	rewrite /wp-admin$ $scheme://$host$uri/ permanent;
	location ~* ^/wp-content/uploads/.*\.php$ {
	  deny all;
	}

5. Check the directory permissions. I found that for some files in the WordPress directory, the permission user and group were no longer www, but root. This was probably because the files in the WordPress directory were copied by the root user, as shown in Figure 3

Check the directory permissions. I found that for some files in the WordPress directory, the permission user and group were no longer www, but root. This was probably because the files in the WordPress directory were copied by the root user
Figure 3

6. When file permission issues occur, execute the following 3 commands in sequence to set the permission user and group to www, resetting the entire /data/wwwroot/ directory, as shown in Figure 4

When file permission issues occur, execute the following 3 commands in sequence to set the permission user and group to www, resetting the entire /data/wwwroot/ directory
Figure 4
Bash

chown -R www.www /data/wwwroot/
find /data/wwwroot/ -type d -exec chmod 755 {} \;
find /data/wwwroot/ -type f -exec chmod 644 {} \;

7. Edit /data/wwwroot/www.aaaacn.net/wp-config.php to set the authentication keys and salts, as shown in Figure 5

Edit /data/wwwroot/www.aaaacn.net/wp-config.php to set the authentication keys and salts
Figure 5

8. Enable “debug” mode across the entire WordPress installation by editing /data/wwwroot/www.aaaacn.net/wp-config.php

PHP


define('WP_DEBUG', true);
define( 'WP_DEBUG_LOG', true );

9. Set whether error messages are displayed on the screen as part of the output, and set it to yes. Edit /data/wwwroot/www.aaaacn.net/wp-admin/install.php. These two options are turned off in phpinfo, as shown in Figure 6

Set whether error messages are displayed on the screen as part of the output, and set it to yes. Edit /data/wwwroot/www.aaaacn.net/wp-admin/install.php. These two options are turned off in phpinfo
Figure 6
PHP

error_reporting(-1);
ini_set('display_errors', '1');
ini_set('log_errors', '1');

10. Open the URL: http://www.aaaacn.net/wp-admin/install.php, and the detailed information for the HTTP ERROR 500 error appears, as shown in Figure 7

Open the URL: http://www.aaaacn.net/wp-admin/install.php, and the detailed information for the HTTP ERROR 500 error appears
Figure 7
Plaintext


Warning: require(/data/wwwroot/www.aaaacn.net/wp-includes/load.php): failed to open stream: No such file or directory in /data/wwwroot/www.aaaacn.net/wp-settings.php on line 19

Warning: require(/data/wwwroot/www.aaaacn.net/wp-includes/load.php): failed to open stream: No such file or directory in /data/wwwroot/www.aaaacn.net/wp-settings.php on line 19

Fatal error: require(): Failed opening required '/data/wwwroot/www.aaaacn.net/wp-includes/load.php' (include_path='.:/usr/local/php/lib/php') in /data/wwwroot/www.aaaacn.net/wp-settings.php on line 19

11. Analysis: /data/wwwroot/www.aaaacn.net/wp-includes/load.php, the file does not exist, as shown in Figure 8

Analysis: /data/wwwroot/www.aaaacn.net/wp-includes/load.php, the file does not exist
Figure 8

12. I decided to delete all files in /data/wwwroot/www.aaaacn.net, download the installation package again, extract it, and copy the files to /data/wwwroot/www.aaaacn.net. I verified that load.php already exists, and set the permission user and group to www, as shown in Figure 9

I decided to delete all files in /data/wwwroot/www.aaaacn.net, download the installation package again, extract it, and copy the files to /data/wwwroot/www.aaaacn.net. I verified that load.php already exists, and set the permission user and group to www
Figure 9
Bash

wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar -xzvf latest-zh_CN.tar.gz
cp -rf /root/wordpress/* /data/wwwroot/www.aaaacn.net
chown -R www.www /data/wwwroot/
find /data/wwwroot/ -type d -exec chmod 755 {} \;
find /data/wwwroot/ -type f -exec chmod 644 {} \;

13. Open the URL: http://www.aaaacn.net/wp-admin/install.php, and it works normally as expected. I am not sure why load.php was missing after extraction earlier? As shown in Figure 10

Open the URL: http://www.aaaacn.net/wp-admin/install.php, and it works normally as expected. I am not sure why load.php was missing after extraction earlier?
Figure 10

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系