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

Ubuntu 18.04降级至16.04或解决Apache2上PHP运行问题

Hey there! Let's break down your two options clearly—downgrading to Ubuntu 16.04, or fixing the Apache-PHP issue on 18.04. I'd strongly recommend the second option since downgrading carries significant risks, but I'll cover both paths for you.

Ubuntu doesn't officially support downgrading between major releases, so this process is prone to dependency conflicts, broken packages, or even a non-bootable system. Backup all critical data first—this is non-negotiable.

  • First, back up your important files (home directory, configs, web content) to an external drive using a tool like tar:
    sudo tar -czvf /path/to/external/storage/server-backup.tar.gz /home /etc /var/www
    
  • Update your apt sources to point to Ubuntu 16.04 (code name xenial) instead of 18.04 (bionic):
    sudo sed -i 's/bionic/xenial/g' /etc/apt/sources.list
    
  • Refresh the package list and start the downgrade process:
    sudo apt update
    sudo apt dist-upgrade -y
    
  • Once the process finishes, reboot your server:
    sudo reboot
    

Warning: If you encounter package conflicts during the downgrade, you may need to force remove problematic packages or even reinstall the system from scratch and restore your backup.

This is the safer, more sustainable path. Let's troubleshoot common issues step by step:

  • Install and enable the PHP Apache module: Ubuntu 18.04 ships with PHP 7.2 by default. Install the module and enable it:
    sudo apt install libapache2-mod-php7.2
    sudo a2enmod php7.2
    sudo systemctl restart apache2
    
  • Test PHP parsing: Create a simple test file in your web root to verify PHP works:
    echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
    
    Visit this file via your server's URL (e.g., http://your-server-ip/info.php). If you see a detailed PHP info page, parsing is working. If you see raw PHP code, the module isn't enabled properly.
  • Check Apache configuration: Ensure Apache is set to handle .php files. Verify the php7.2.conf file has this rule:
    <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    
  • If using PHP-FPM: If you prefer using PHP-FPM instead of mod_php, install and configure it:
    sudo apt install php7.2-fpm
    sudo a2enmod proxy_fcgi setenvif
    sudo a2enconf php7.2-fpm
    sudo systemctl restart apache2 php7.2-fpm
    
  • Check error logs: If problems persist, dig into the logs for clues:
    • Apache error log: sudo tail -n 20 /var/log/apache2/error.log
    • PHP-FPM log (if applicable): sudo tail -n 20 /var/log/php7.2-fpm.log

内容的提问来源于stack exchange,提问作者pitwo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:37:03