How To Save a Broken Wordpress Site From PHP7 Upgrade

I upgraded my old server from Ubuntu 14.04 to 18.04, and during that upgrade process, PHP is upgraded from 5.6 to 7.2. As expected 🙄, my wordpress site is not working with this upgrade. Following is how I saved my wordpress site and make it functional again.

  1. Reinstall PHP 5.6

    1
    2
    3
    $sudo add-apt-repository ppa:ondrej/php
    $sudo apt-get update
    $sudo apt-get install php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php-xdebug libapache2-mod-php5.6
  2. Switch Apache server to use PHP 5.6

    1
    $sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

    You should verify that mods-enabled folder has php 5.6 mods:

    1
    2
    3
    4
    5
    $pwd
    /etc/apache2/mods-enabled
    $ls -l php5.6.*
    lrwxrwxrwx 1 root root 29 May 13 00:05 php5.6.conf -> ../mods-available/php5.6.conf
    lrwxrwxrwx 1 root root 29 May 13 00:05 php5.6.load -> ../mods-available/php5.6.load
  3. Done! Your site should be working again.

Reference:

Reinstall PHP 5.6