When facing the decision to upgrade an Ubuntu 18.04 server, you basically have two choices:
Lower Risk Scenario
1. Upgrade just PHP. The hero in this story is ondrej. We think it’s a person, but he/she is hard to find.
Once you’ve followed the steps below for upgrading using the ondrej repos, use this command to set the new version:
update-alternatives --config php
Although this is low risk, you could have issues, so make a mirror backup of the server first.
Very High Risk Scenario
2. Upgrade the OS
Why should you even consider upgrading the OS when it’s high risk?
Here are the reasons:
a. As of this article date 17 August 2021 Ubuntu 18.04 is three years old and no longer the LTS version. You are on the edge of having an outdated server.
b. Ubuntu 20.04 comes with PHP 7.4 by default.
Upgrade Steps Lower Risk Scenario
Should you wish to just upgrade PHP, do this:
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
And then install the foundation PHP:
sudo apt install php7.4
Add a bunch of packages just in case:
sudo apt install php7.4-common php7.4-cli php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-readline php7.4-xml php7.4-zip php7.4-fpm
Upgrading to PHP 8
sudo apt-get install php8.0 php8.0-fpm php8.0-mysql php8.0-mbstring php8.0-xml php8.0-gd php8.0-curl php8.0-zip
You’re might be running Apache. Disable and enable PHP for it but only if you’re not running Virtualmin:
#sudo a2dismod php7.3
#sudo a2enmod php7.4
#sudo service apache2 restart
High Risk Scenario
root@server:~# do-release-upgrade Checking for a new Ubuntu release Please install all available updates for your release before upgrading.
Ioncube Issues?
First see where your INI file lives, e.g.:
# php -i | grep php.ini Failed loading /usr/lib/php/20190902/ioncube_loader_lin_7.3.so: /usr/lib/php/20190902/ioncube_loader_lin_7.3.so: cannot open shared object file: No such file or directory Configuration File (php.ini) Path => /etc/php/7.4/cli Loaded Configuration File => /etc/php/7.4/cli/php.ini
In this particular instance it was useless, because ioncube isn’t loaded via that php.ini file, instead being includes from another directory:
/etc/php/7.4/cli/conf.d
In there you’ll find symbolic links to the actual files, e.g.:
root@server:/etc/php/7.4/cli/conf.d# ls -lah total 12K drwxr-xr-x 2 root root 4.0K Aug 18 04:37 . drwxr-xr-x 3 root root 4.0K Apr 12 2020 .. -rw-r--r-- 1 root root 65 Aug 18 04:37 00-ioncube.ini lrwxrwxrwx 1 root root 39 Apr 12 2020 10-mysqlnd.ini -> /etc/php/7.4/mods-available/mysqlnd.ini
Fix the above symbolic link, and then make sure:
ioncube_loader_lin_7.4.so
is stored in/usr/lib/php/20190902
ioncube_loader_lin_7.3.so
is stored in/usr/lib/php/20180731
You would think after all these years ioncube have made it easy to install their loader, but no, you still have to jump through hoops when it’s not working.
Reference
Normally we’re very proud and diligent in pasting our references here, but in this case the reference comes with a big warning. THIS REFERENCE IS SO RIDICULOUS SPAMMY THAT IT WILL HOG YOU’RE PC’S CPU. Loads of crappy Javascript and advertisements. Hopefully I never have to click on it again.
You’ve been warned.