Ubuntu 16.4下phpMyAdmin无法显示登录界面问题求助
Hey there, let's sort out this phpMyAdmin problem where you're seeing raw PHP code instead of the login screen. This usually happens because Apache isn't properly parsing PHP files, or the phpMyAdmin configuration isn't correctly linked to your web server. Here's a step-by-step guide to get it working:
1. Ensure Apache has the PHP module installed and enabled
First, we need to make sure PHP and the Apache PHP module are installed and active (Ubuntu 16.04 uses PHP 7.0 by default):
- Install the required packages:
sudo apt-get update && sudo apt-get install php libapache2-mod-php - Enable the PHP module:
sudo a2enmod php7.0 - Restart Apache to apply changes:
sudo systemctl restart apache2
2. Verify phpMyAdmin's Apache configuration is enabled
Sometimes the phpMyAdmin config isn't automatically added to Apache's active configurations:
- Enable the phpMyAdmin config file:
sudo a2enconf phpmyadmin.conf - Restart Apache again to load the new config:
sudo systemctl restart apache2
3. Test if PHP is being parsed correctly
Let's create a simple test file to confirm Apache can process PHP:
- Create a file named
info.phpin your web root:sudo nano /var/www/html/info.php - Paste this content into the file:
<?php phpinfo(); ?> - Save and exit (press
Ctrl+O, hitEnter, thenCtrl+X). - Visit
http://localhost/info.phpin your browser. If you see a detailed PHP info page, Apache is parsing PHP correctly. If not, double-check the PHP installation steps above.
4. Fix file permissions for phpMyAdmin
Incorrect permissions can prevent Apache from accessing phpMyAdmin's files properly:
- Set the correct owner for phpMyAdmin files:
sudo chown -R www-data:www-data /usr/share/phpmyadmin - Set proper directory and file permissions:
sudo chmod -R 755 /usr/share/phpmyadmin
5. Make sure index.php is prioritized by Apache
Apache might be trying to load index.html before index.php, which can cause issues:
- Edit the directory index configuration:
sudo nano /etc/apache2/mods-enabled/dir.conf - Ensure
index.phpis the first entry in theDirectoryIndexline, like this:DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm - Save and exit, then restart Apache:
sudo systemctl restart apache2
After going through these steps, try accessing http://localhost/phpmyadmin again—you should see the login screen now. If you still run into issues, double-check that all commands ran without errors, and verify Apache is running with sudo systemctl status apache2.
内容的提问来源于stack exchange,提问作者Nam's

