Ubuntu20.04中访问phpMyAdmin显示原始代码的问题求助
Hey there, let’s work through this issue where phpMyAdmin is displaying raw code instead of its proper interface. This almost always boils down to Apache not being configured to parse PHP files correctly—let’s go through targeted checks and fixes step by step:
1. Verify PHP is Installed & Apache’s PHP Module is Enabled
First, make sure PHP and the Apache PHP module are set up properly:
- Check if PHP is installed on your system:
If you get an error, install PHP 7.4 (Ubuntu 20.04’s default version) along with the Apache module:php -vsudo apt update && sudo apt install php7.4 libapache2-mod-php7.4 - Enable the PHP module in Apache and restart the service to apply changes:
sudo a2enmod php7.4 sudo systemctl restart apache2
2. Validate Apache’s PHP Configuration
Ensure Apache knows to parse .php files instead of serving them as plain text:
- Open the PHP module config file:
sudo nano /etc/apache2/mods-available/php7.4.conf - Confirm it includes these critical rules (they tell Apache how to handle PHP files):
<FilesMatch ".+\.ph(p[3457]?|t|tml)$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch ".+\.phps$"> SetHandler application/x-httpd-php-source Require all denied </FilesMatch> <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$"> Require all denied </FilesMatch> - If the config is missing or corrupted, reinstall the Apache PHP module to reset it:
sudo apt reinstall libapache2-mod-php7.4 - Restart Apache again after making any edits:
sudo systemctl restart apache2
3. Check phpMyAdmin’s Apache Configuration Link
phpMyAdmin needs its config file to be linked to Apache’s enabled config directory. Let’s confirm this:
- Check if the link exists:
ls /etc/apache2/conf-enabled/ | grep phpmyadmin - If you don’t see
phpmyadmin.conf, create the symlink manually:sudo ln -s /etc/apache2/conf-available/phpmyadmin.conf /etc/apache2/conf-enabled/phpmyadmin.conf - Restart Apache to apply the change:
sudo systemctl restart apache2
4. Test Basic PHP Parsing
To rule out broader Apache-PHP integration issues, create a simple test file:
- Create
info.phpin your web root directory:sudo nano /var/www/html/info.php - Add this content to the file:
<?php phpinfo(); ?> - Save the file and visit
localhost/info.phpin your browser:- If you see a formatted PHP info page: PHP parsing works, so the issue is specific to phpMyAdmin.
- If you still see raw code: Go back to steps 1-2 to fix Apache’s PHP setup.
5. Fix phpMyAdmin File Permissions
Incorrect file permissions can cause unexpected behavior. Ensure the web server user owns the phpMyAdmin files:
sudo chown -R www-data:www-data /usr/share/phpmyadmin/
6. Debug with Apache Error Logs
If none of the above fixes work, check Apache’s error logs for specific clues:
- View the latest log entries in real time:
sudo tail -f /var/log/apache2/error.log - Refresh the phpMyAdmin page in your browser, then look for error messages in the terminal—these will point you to the exact issue (e.g., missing dependencies, broken config lines).
内容的提问来源于stack exchange,提问作者Kenechukwu Nwobodo

