Debian 10环境下WordPress本地部署异常:localhost显示文件索引而非配置页,修改Apache配置后出现空白页
Hey there, let's work through this WordPress deployment issue you're hitting on Debian 10 together! First, let me recap what you've tried and the problem you're seeing to make sure I'm on the same page:
What You've Done So Far
- Edited Apache's default config file with:
sudo {editor of choice} 000-default.conf(replacing the placeholder with your preferred editor like nano or vim) - Changed the
DocumentRootvalue toDocumentRoot /var/www/html/wordpress, saved the file, then restarted Apache withsudo service apache2 restart - The Problem: After making this change, visiting
localhostshows a blank page. If you revertDocumentRootback to/var/www/html, you only get an "Index Of/" page instead of the expected WordPress setup wizard.
Troubleshooting Steps to Fix This
Let's go through the most common causes and fixes step by step:
Verify WordPress Files & Permissions
- First, make sure the
/var/www/html/wordpressdirectory actually has all the core WordPress files (likewp-config-sample.php,wp-admin,wp-content). Run this command to check:ls -la /var/www/html/wordpress - If the files are there, the next big culprit is usually incorrect permissions. Apache runs as the
www-datauser, so it needs read access to these files. Fix permissions with these commands:sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress - After adjusting permissions, restart Apache again:
sudo service apache2 restartand checklocalhostonce more.
- First, make sure the
Check Apache Error Logs for Clues
- Blank pages almost always mean there's a server-side error that's not being displayed. Let's look at Apache's error log to find out what's going wrong:
sudo tail -f /var/log/apache2/error.log - Keep this terminal open, then refresh your
localhostpage in the browser. You'll see error messages pop up here—things like missing files, permission denied, or PHP module issues will be clearly listed.
- Blank pages almost always mean there's a server-side error that's not being displayed. Let's look at Apache's error log to find out what's going wrong:
Ensure PHP is Installed & Enabled
- WordPress relies on PHP to run, so if PHP isn't installed or Apache isn't configured to use it, you'll get blank pages or even download prompts instead of the setup wizard.
- Check if PHP is installed:
php -v - If it's not installed, install PHP and the required modules for WordPress:
sudo apt update sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip - Enable the PHP module (if not already enabled) and restart Apache:
sudo a2enmod php7.3 # 注:Debian 10默认使用PHP 7.3,若你安装了其他版本请对应调整 sudo service apache2 restart
Check Your Apache Directory Configuration
- Just changing the
DocumentRootmight not be enough—you need to make sure Apache is configured properly to handle the/var/www/html/wordpressdirectory. Open your000-default.conffile again and add or verify this block:<Directory /var/www/html/wordpress> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> - This tells Apache to allow access to the directory, follow symbolic links, and enable
.htaccesssupport (which WordPress needs for permalinks later). Save the file and restart Apache.
- Just changing the
Confirm Your Database is Set Up & Running
- WordPress requires a MySQL/MariaDB database to store its data. If you skipped this step in the guide, that's likely causing issues:
- Check if MariaDB is running:
sudo service mariadb status - If it's not running, start it:
sudo service mariadb start - You'll need to create a dedicated database and user for WordPress. If you haven't done this, run
sudo mysql -u root -pand execute these commands (replacewp_db,wp_user, andyour_passwordwith your own values):CREATE DATABASE wp_db; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
- Check if MariaDB is running:
- WordPress requires a MySQL/MariaDB database to store its data. If you skipped this step in the guide, that's likely causing issues:
Final Notes
If you still see the "Index Of/" page when DocumentRoot is set to /var/www/html, that means Apache is listing the directory contents instead of loading WordPress's index.php file. To fix this, make sure the DirectoryIndex directive in your Apache config is set to prioritize index.php:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
You can add this line either in your 000-default.conf file or in the <Directory /var/www/html/wordpress> block we added earlier.
备注:内容来源于stack exchange,提问作者Thomas Simpson

