AWS EC2实例中WordPress主题及登录页CSS/HTML加载失败求助
Hey there, let's walk through targeted fixes for your WordPress CSS/HTML loading problem—since you've already checked wp-config.php and Apache MIME settings, let's focus on other common root causes:
Verify File Permissions
Incorrect file permissions are a super common culprit for static resource failures. On most AWS EC2 setups (Amazon Linux/RHEL), run these commands to set proper ownership and permissions:# Set Apache as the owner of WordPress files sudo chown -R apache:apache /var/www/html # Set directory permissions to 755 sudo find /var/www/html -type d -exec chmod 755 {} \; # Set file permissions to 644 sudo find /var/www/html -type f -exec chmod 644 {} \;For Debian/Ubuntu systems, replace
apache:apachewithwww-data:www-data.Check mod_rewrite and .htaccess Configuration
WordPress relies onmod_rewritefor clean URLs and proper resource routing:- Enable the module (Debian/Ubuntu):
For Amazon Linux/RHEL, it's usually enabled by default, but restart Apache to confirm:sudo a2enmod rewrite sudo systemctl restart apache2sudo systemctl restart httpd - Ensure your Apache virtual host allows
.htaccessoverrides. Edit your site's config file (e.g.,/etc/httpd/conf.d/your-site.conf) and add/update this directive inside the<Directory>block:AllowOverride All - Replace your
.htaccessfile in the WordPress root with the default WordPress rules (backup the old one first):# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
- Enable the module (Debian/Ubuntu):
Confirm Site URL Settings
Mismatched site URLs can break resource paths. Add these lines to yourwp-config.php(replace with your actual domain):define('WP_HOME', 'http://your-domain'); define('WP_SITEURL', 'http://your-domain');This overrides the database settings and ensures WordPress uses the correct base URL for loading CSS/JS.
Inspect Browser Console Errors
Open your browser's developer tools (F12) and check the Console tab for specific errors:- A
404 Not Foundmeans the resource path is incorrect (likely URL/rewrite issue) - A
403 Forbiddenpoints to permission problems - A
500 Internal Server Errorindicates a server config or script issue
Sharing these errors will help narrow down the problem faster.
- A
Check Apache Error Logs
Dig into Apache's error logs for server-side issues:- Amazon Linux/RHEL:
/var/log/httpd/error_log - Debian/Ubuntu:
/var/log/apache2/error.log
Run this command to view recent logs:
sudo tail -20 /var/log/httpd/error_log- Amazon Linux/RHEL:
If none of these steps resolve the issue, share the browser console errors and Apache log snippets, and we can dive deeper!
内容的提问来源于stack exchange,提问作者Alejandro Chiriboga

