Upgrade Ubuntu 18.04 to 20.04
Ubuntu 18.04 (“Bionic Beaver”) stopped receiving security updates from Ubuntu on May 31, 2023. To continue receiving updates from Ubuntu, you must upgrade Ubuntu.
::: Operating system upgrades are risky. If the upgrade fails, your server will become unusable. It is often better to migrate your apps to a new server running the latest version of Ubuntu. :::
Preparing to Upgrade
It is critical that you take a snapshot of your server before upgrading Ubuntu.
You can take a snapshot of your server through your server provider’s control panel.
::: Do not proceed with the upgrade until you’ve taken a snapshot of your server. :::
Ensure Enough Memory is Available
If your server has 1GB of memory or less, you should increase the server’s memory before starting the upgrade or else the upgrade may fail. After the upgrade is complete, you can decrease the server’s memory.
Apply available updates and reboot
Once you’ve taken a snapshot of your server and made sure it has enough
memory, SSH in to your server as root
and run
the following command to make sure your server is ready to be upgraded
to a new version of Ubuntu.
sudo apt-get update && sudo apt-get -y dist-upgrade && sudo dpkg --configure -a
If the above command fails or prints an error message, do not proceed with upgrading.
Once all packages have been updated, reboot your server by running this command:
sudo reboot
Check MySQL 8.0 configuration compatibility
Ubuntu 20.04 uses MySQL 8.0. Some configuration options that were valid
in MySQL 5.7 are no longer valid in MySQL 8.0. Most notably, the
sql_mode
value NO_AUTO_CREATE_USER
is no longer supported.
To check your MySQL configuration, run the following command as root
:
sudo grep -R NO_AUTO_CREATE_USER /etc/mysql/
If there is no output from the command, you can proceed with upgrading Ubuntu.
If there is output from the command, remove NO_AUTO_CREATE_USER
from your sql_mode
setting before you upgrade Ubuntu. See this
article for more
information.
Make sure all apps are using PHP 7.2 or greater
PHP versions below PHP 7.2 are not available on Ubuntu 20.04. If any apps are using PHP versions below PHP 7.2, you must switch them to using PHP 7.2 or any higher PHP version before proceeding with the upgrade.
Make sure no apps on the server are using a PHP version below PHP 7.2. For each app, go to the app’s “Settings” page in ServerPilot and verify the app is using PHP 7.2 or greater. For any app using a PHP version below PHP 7.2, change the app to use PHP 7.2 and then verify the app still works correctly. If the app is not working on PHP 7.2, do not upgrade Ubuntu until the app’s code is fixed to support at least PHP 7.2.
Uninstall PHP packages
Uninstall all PHP packages by running the following command as root
:
sudo apt-get -y remove 'sp-php*'
Performing the Upgrade
::: All of the apps on your server will be down during the upgrade. Depending on your server’s network connection and hardware, the upgrade may take anywhere from ten minutes to two hours. :::
To upgrade your server from Ubuntu 18.04 to Ubuntu 20.04, SSH into your
server as root
and run the following command:
sudo do-release-upgrade -f DistUpgradeViewNonInteractive
If you encounter problems or the upgrade fails, take screenshots of any errors and then restore your server to the snapshot you made before you began the upgrade. Once your server has been restored from a working snapshot, please contact support and provide us the details of the errors.
After the Upgrade
Reboot your server
Once the upgrade is complete, reboot your server by running the following command:
sudo reboot
Update the package manager configuration
Run the following command to update the package manager’s configuration for ServerPilot’s repositories:
sudo bash -c "echo 'deb [signed-by=/usr/share/keyrings/serverpilot.gpg] https://download.serverpilot.io/ubuntu focal main' > /etc/apt/sources.list.d/serverpilot.list"
You can verify the file is correct by running the following command:
sudo cat /etc/apt/sources.list.d/serverpilot.list
You should see the following output from the above command:
deb [signed-by=/usr/share/keyrings/serverpilot.gpg] https://download.serverpilot.io/ubuntu focal main
Next, update the package manager’s list of available packages by running this command:
sudo apt-get update
Then run the following command to install any package updates that are now available:
sudo apt-get -y dist-upgrade
Reinstall PHP packages
Install the versions of PHP that are supported on Ubuntu 20.04 by running the following command
sudo apt-get -y install sp-php7.2 sp-php7.3 sp-php7.4 sp-php8.0 sp-php8.1 sp-php8.2 sp-php8.3 sp-php8.4
After you install these PHP packages, if you do not see any of these PHP versions available in ServerPilot when choosing the PHP version for apps on this server (that is, when editing an app’s PHP version on the app’s “Settings” page), please contact support so we can enable the missing PHP versions for you.
Update the PHP version used for the “php
” command
Update the version of PHP used for the PHP-CLI (the “php
” command) by
running the following command as root
:
sudo dpkg-reconfigure sp-php-cli
Select the version of PHP you’d like to be the default for the “php
”
command.
Regardless of which PHP version you chose as the CLI default, you can
access any PHP-CLI version by using a version-specific “php
”
command.
Recompile PECL extensions
If you’ve previously installed any PECL extensions on your server, you should now recompile them. See how to recompile PECL extensions.
Take a server snapshot
As the final step, take a snapshot of your server now that the upgrade is complete. All of your existing snapshots are for an older version of Ubuntu. If you needed to restore your server and used one of those older snapshots, you would have to perform the upgrade again.