Upgrade from Ubuntu 18.04 to 20.04 LTS running WordPress + Apache + PHP-fpm
I just upgraded 3 Ubuntu servers from Ubuntu 18.04 to 20.04 LTS that is running WordPress, Apache, MySQL and PHP-fpm stack. There are of course many guides out there on the basic part of the Ubuntu OS upgrade. But if you are running WordPress on Apache using PHP in PHP-fpm mode, there are some key steps to be taken to get your site up and running again.
The Ubuntu 18.04 to 20.04 LTS upgrade guide
This post serves as my checklist of things to do when I upgrade the server. It has worked well for me as it makes sure I don’t forget any important configurations to change or update. I’ve also used this on servers running off Digital Ocean and Linode. So I hope this guide will also serve you well if you are planning to do the same.Make sure the existing server is up to date.
1. Update the existing Ubuntu 18.04 server
Make sure everything is up to date. I would usually also just auto remove any unneeded components from my servers.
sudo apt update && sudo apt upgrade && sudo apt autoremove sudo apt install update-manager-core
2. Upgrade from Ubuntu 18.04 to 20.04 LTS!
First, verify that the release upgrade Prompt is set to lts
Run the release upgrade.
During the release upgrade, there will be a lot of prompts. As you know your server best, you would therefore know what is best for your server. However, I will share that in my upgrades, I accepted all the defaults when prompted. Whenever there are existing configuration files, I would just default to the continue to use existing configurations. I also allowed the release upgrade to automatically remove any old modules or components. Nothing broke, at least in my upgrade experience.
This step will take a while. So, do be patient and be aware of all the prompts that require your response.
Once done, it will finally prompt you to restart the server. When you reconnect back to the server, you can confirm that it has been upgraded to Ubuntu 20.04 LTS by using the following command.
I would usually just run another apt update, upgrade, autoremove just to ensure the server is up to date. But this step is really optional.
sudo apt update && sudo apt upgrade && sudo apt autoremove
3. Check your PHP-fpm installation
The following are a series of checks to ensure the PHP-fpm setup is correct and properly configured. This will vary a lot depending how your PHP installation is originally installed and configured. But the following should point the key configurations to check and ensure it’s properly set up.
Firstly, ensure all the necessary php 7.4 modules generally required by WordPress are installed. On my servers, I used php-fpm. For some reasons, I had the problem of conflicting between fastcgi and fcgid modules. So the following steps are meant to also ensure unnecessary modules are disabled. You can also disable the php7.4 module if you exclusively use php-fpm to serve your PHP sites.
sudo apt install php php-fpm libapache2-mod-fcgid php-curl php-xml php-imagick php-zip php-mysql php-mbstring sudo a2enconf php7.4-fpm sudo a2dismod fastcgi sudo a2dismod php7.4
If you upload large media files on your WordPress site, you will likely need to update the upload_max_filesize and post_max_size settings. Edit the php.ini accordingly. For me, I just set both to 10M.
sudo nano /etc/php/7.4/fpm/php.ini
For a couple of my WordPress sites, I have tuned the php-fpm server pool configurations as well. If you do, remember to also update the /etc/php/7.4/fpm/pool.d/www.conf file. If you know what I’m referring to here, then you would know what you need to do, otherwise, read up on tuning php-fpm or just skip this step since you never had the need to tune your server. 😄
Restart the php-fpm service.
sudo service php7.4-fpm restart
4. Check and update the Apache configurations
Ensure you don’t have any conflicting php-fpm configurations in your apache server configurations.
cd /etc/apache2/conf-enabled/ ls
As I mentioned earlier, depending how php-fpm was installed and configured, you might end up having two php-fpm configurations enabled as I did. One was the new php7.4-fpm.conf that was just enabled. I also had the old php-fpm.conf in the directory. To resolve this, just delete the old php-fpm.conf configuration file.
Next up, update all your enabled-sites configuration.
cd /etc/apache2/conf-enabled/ ls
sudo nano the WordPress (and any other PHP) site configuration files and edit the SetHandler like to now use php7.4-fpm.sock. The old configurations should be php7.2-fpm.sock.
<FilesMatch ".php$"> SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/" </FilesMatch>
5. Reset to use MPM_Event
Lastly, I would also reset Apache to use MPM_Event instead of the default Prefork. Once that’s swapped, restarting the Apache server should get the WordPress site up and running again.
sudo a2dismod mpm_prefork sudo a2enmod mpm_event sudo service apache2 restart
6. Disable MySQL logbin binary logs
Unless you run MySQL in a cluster mode, you are unlikely to need to leave the binary logging enabled. The binary logs can consume your disk space really fast.
To disable the binary logs, edit the mysqld.cnf file and add disable_log_bin in the configuration.
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
I search and the disable_log_bin line where the rest of the log_bin settings where. But you can enter it anywhere in the configuration file after [mysqld]. Then restart the MySQL server when you are done.
sudo service mysql restart
As I’ve mentioned earlier. I’ve used the steps above on the TechARP, Rojakpot and (obviously) this site to upgrade from Ubuntu 18.04 to 20.04 LTS with good outcomes. On all 3 times, I was able to get the site back up without any major problems within 30 mins.
Hopefully, this guide will help you create your own server upgrade checklist too. Write in a comment if you think there are unnecessary or missing steps in my guide here. I would also be happy to help if you are facing any problems with your own server upgrade.