← ServerPilot Docs

How to Upgrade Ubuntu 22.04 to 24.04

Ubuntu 22.04 will stop receiving security updates from Ubuntu in April 2027. To continue receiving updates from Ubuntu after April 2027, you must upgrade your server to Ubuntu 24.04.

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

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 22.04 to Ubuntu 24.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 noble 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 noble 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 24.04 by running the following command

sudo apt-get -y install 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: April 23, 2024

Launch your first site in 5 minutes