← ServerPilot Docs

How to Upgrade Ubuntu 16.04 to 18.04

Ubuntu 16.04 stopped receiving security updates from Ubuntu in April 2021.

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.

Apply available updates and reboot

Once you've taken a snapshot of your server, 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

Make sure all apps are using PHP 5.6 or greater

PHP versions below PHP 5.6 are not available on Ubuntu 18.04. If any apps are using PHP versions below PHP 5.6, you must switch them to using PHP 5.6 or any higher PHP version before proceeding with the upgrade.

Make sure no apps on the server are using a PHP version below PHP 5.6. For each app, go to the app's "Settings" page in ServerPilot and verify the app is using PHP 5.6 or greater. For any app using a PHP version below PHP 5.6, change the app to use PHP 5.6 and then verify the app still works correctly. If the app is not working on PHP 5.6, do not upgrade Ubuntu until the app's code is fixed to support at least PHP 5.6.

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 16.04 to Ubuntu 18.04, SSH in to 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 bionic 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 bionic 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 18.04 by running the following command

sudo apt-get -y install sp-php5.6 sp-php7.0 sp-php7.1 sp-php7.2 sp-php7.3 sp-php7.4 sp-php8.0 sp-php8.1 sp-php8.2 sp-php8.3

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.

Last updated: November 20, 2023

Launch your first site in 5 minutes