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

Ubuntu 16.04服务器上为Magento 2将PHP7.2降级至7.0的方法求助

Downgrade PHP from 7.2 to 7.0 on Ubuntu 16.04 for Magento

Hey there, let's get your PHP version downgraded from 7.2 to 7.0 on Ubuntu 16.04 for Magento (including Magento 2) — I've walked through this a few times, so here's a step-by-step that should work reliably:

1. Completely Uninstall PHP 7.2

First, we need to wipe out all traces of PHP 7.2 to avoid version conflicts later:

  • Stop your web server first (adjust for Apache or Nginx):
    # For Apache
    sudo systemctl stop apache2
    
    # For Nginx
    sudo systemctl stop nginx
    
  • Purge PHP 7.2 packages and leftover dependencies:
    sudo apt-get purge php7.2*
    sudo apt-get autoremove
    sudo apt-get autoclean
    
  • Verify no PHP 7.2 packages remain (remove any stragglers if they show up):
    dpkg -l | grep php
    

2. Add PHP 7.0 Repository

Ubuntu 16.04's default repos include PHP 7.0, but using a trusted PPA ensures we get stable, maintained packages:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

This PPA is widely used for maintaining legacy PHP versions, so it's a safe bet for our downgrade.

3. Install PHP 7.0 & Magento-Required Extensions

Magento (especially Magento 2) relies on specific PHP extensions to function properly. Install them alongside PHP 7.0:

  • For Apache (using mod_php):
    sudo apt-get install php7.0 php7.0-cli libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php7.0-mbstring php7.0-xml php7.0-zip php7.0-soap
    
  • For Nginx (using PHP-FPM):
    sudo apt-get install php7.0 php7.0-cli php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php7.0-mbstring php7.0-xml php7.0-zip php7.0-soap
    

4. Set PHP 7.0 as the Default Version

If any other PHP versions are still installed, switch the system default to 7.0:

sudo update-alternatives --set php /usr/bin/php7.0

Verify the change with:

php -v

You should see output starting with PHP 7.0.x if everything worked.

5. Reconfigure Your Web Server

  • For Apache:
    Disable the old PHP 7.2 module, enable PHP 7.0, then restart Apache to apply changes:
    sudo a2dismod php7.2
    sudo a2enmod php7.0
    sudo systemctl restart apache2
    
  • For Nginx:
    Open your site's Nginx configuration file (usually in /etc/nginx/sites-available/) and update the fastcgi_pass line to point to PHP 7.0-FPM:
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    
    Save the file and restart Nginx:
    sudo systemctl restart nginx
    

6. Verify Web Server PHP Version

Create a temporary info file to confirm the web server is using PHP 7.0:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit http://your-server-ip/info.php in a browser — you should see PHP 7.0 listed at the top. Don't forget to delete this file afterward for security:

sudo rm /var/www/html/info.php

Quick Tips

  • Double-check that all Magento-required extensions are enabled (use php -m or the info.php page to confirm). Missing extensions will cause Magento installation or runtime errors.
  • If you hit package conflicts, run sudo apt-get -f install to resolve dependency issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:10:49