Upgrade Ubuntu Server 20.04 to 22.04 with Apache, MySQL, PHP web stack
Looking for a quite to upgrade Ubuntu server 20.04 to 22.04 LTS? Have Apache, MySQL DB and PHP-fpm configured and running on the server? Here’s how I’ve managed to get my own server upgraded under an hour.
The whole process is very similar as when I upgraded my server from 18.04 to 20.04 LTS.
Steps to upgrade Ubuntu server 20.04 to 22.04
1. Backup your server!
Seriously. Back it up. On Linode where my server is hosted, I can easily take a snapshot of my server’s storage. If anything goes wrong, I can easily restore the server with the backup.

2. Make sure its up to date
As always, it’s prudent to update and upgrade all current modules and services installed on the server. Though optional, I recommend rebooting the server to make sure everything is fresh and good.
sudo apt update -y && sudo apt upgrade -y && sudo apt dist-upgrade -y sudo apt autoremove -y && sudo apt autoclean -y sudo reboot
3. Time to stop Apache and MySQL
You don’t want to risk any data corruption during the upgrade process. So it’s best to shut down the Apache and MySQL service. Yes, there will be downtime if you plan to do an in-place upgrade.
sudo systemctl stop apache2 sudo systemctl stop mysql
4. Let’s make sure you have everything you need for the upgrade
update-manager-core should already be installed. But let’s make sure anyway.
sudo apt install update-manager-core
5. Check that LTS will be installed
Assuming you want to install the LTS release, let’s make sure the update manager will get the LTS release for 22.04. You should see “Prompt=lts” in the output.
sudo cat /etc/update-manager/release-upgrades

6. Time for the big upgrade!
As mentioned, my server is hosted on Linode and the sources in the /etc/apt/sources.list is actually pointing to Linode’s mirror and I also have a couple of 3rd party sources in /etc/apt/sources.list.d. So by just using the regular “do-release-upgrade” command, I get the following error: –
Invalid package information
After updating your package information, the essential package
'ubuntu-minimal' could not be located. This may be because you have
no official mirrors listed in your software sources, or because of
excessive load on the mirror you are using. See /etc/apt/sources.list
for the current list of configured software sources.
In the case of an overloaded mirror, you may want to try the upgrade
again later.
So, I had to use override it to allow third party sources.
RELEASE_UPGRADER_ALLOW_THIRD_PARTY=1 do-release-upgrade
At this point, just follow the instructions and let the upgrade process do its job.
In my case, phpmyadmin was uninstalled in the process. As it did that, it prompted me if I wanted to remove its phpmyadmin database. Since I will continue using it, I made sure to select the options to not remove the database. Anyway, since the MySQL service is not running, it won’t be able to remove the database anyway.
When you get prompted it you want to keep any of the existing configuration files, make sure you select ‘N’, which is to keep the existing configuration files.
The whole upgrading process didn’t take too long in my case, probably about 15 mins?
When done, it will prompt you to restart the server. Go ahead and restart it. Once the server comes back online, let’s make sure its finally upgraded from 20.04 to 22.04 Jammy release.
lsb_release -a

Alternatively, you can get this information from /etc/os-release
cat /etc/os-release

7. If removed, reinstall phpMyAdmin
I installed phpMyAdmin via apt and I just need it to reinstall back to its default /usr/share/phpmyadmin/ directory.
sudo apt install phpmyadmin
8. Reinstall php extensions as required for the new php 8.1 version.
Always good to make sure all the extensions you need are installed. The following is based on my server’s needs. Add or remove the list as needed for your server.
sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-mbstring php8.1-opcache php8.1-zip php8.1-intl -y
8. Edit php.ini as required
I need to increase the upload_max_filesize to allow me to upload larger files on WordPress. A tip when using nano, use ctrl-w to search.
sudo nano /etc/php/8.1/fpm/php.ini
upload_max_filesize = 50M
post_max_size = 50M
9. Make sure PHP-FPM is enabled and disable php7.4, php8.1 module on Apache
I use PHP-FPM on my server. Thus, I want to make sure the necessary modules and configurations are in place.
sudo a2dismod php7.4 sudo a2dismod php8.1 sudo a2disconf php7.4-fpm sudo a2enmod proxy_fcgi setenvif sudo a2enconf php8.1-fpm
10. Configure Apache to use mpm_event
Again, I’ve always configured Apache to use mpm_event instead of the default mpm_prefork.
sudo a2dismod mpm_prefork sudo a2enmod mpm_event
11. Finally, it’s time to edit the apache sites .conf to point to the php8.1-fpm
The release upgrade is not smart enough to make this configuration change, nor do you actually want it to mess around with your apache site configuration files.
As usual, I use nano to edit files on my server.
/etc/apache2/sites-enabled/your-site.conf
In the configuration file, edit php7.4-fpm.sock to php8.1-fpm.sock.
<FilesMatch ".php$">
SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost/"
</FilesMatch>
Do this for all your PHP-based sites. When done, reload the apache service.
sudo service apache2 reload
Upgrade Ubuntu Server 20.04 to 22.04 is now done!
At this point, your WordPress site should be up and running again! It took me a total of 28 mins to complete this whole process, including fumbling around trying to remember what I needed to do. π

With this guide, I hope your upgrade process would be a lot smoother and faster.
If this post has been useful, support me by buying me a latte or two π
