You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu20.04中访问phpMyAdmin显示原始代码的问题求助

Fixing phpMyAdmin Showing Raw Code on Ubuntu 20.04

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:
    php -v
    
    If you get an error, install PHP 7.4 (Ubuntu 20.04’s default version) along with the Apache module:
    sudo 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
    

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.php in 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.php in 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:59:59