Upgrading Ubuntu from version 20.04 to 22.04 is an exciting step that brings performance improvements, new features, and enhanced security. However, as with any major upgrade, you may encounter issues that need to be resolved to get your server running smoothly again. One common problem many users face during this upgrade is related to Nginx and PHP compatibility.
The Problem: Nginx Not Found After Upgrade
After upgrading to Ubuntu 22.04, some users report that when they try to access their websites, they encounter the error “Nginx not found” or the site simply does not load as expected. This can be a frustrating experience, especially if your Nginx setup was working perfectly on Ubuntu 20.04.
Upon investigation, the main issue is that Ubuntu 22.04 does not work well with PHP 7.4, which was widely used in Ubuntu 20.04. Ubuntu 22.04 is designed to work with newer versions of PHP, and PHP 8.1 is the recommended version for this distribution.
Solution: Upgrading PHP from 7.4 to 8.1
To resolve this issue, you will need to upgrade PHP to version 8.1 or higher and update your website’s configuration files. Follow these steps to fix the issue:
1. Install PHP 8.1
If PHP 8.1 is not already installed on your system, you can install it with the following commands:
sudo apt update sudo apt install php8.1 php8.1-fpm php8.1-cli php8.1-mbstring php8.1-xml php8.1-mysql
This will install PHP 8.1 and the necessary extensions for Nginx.
2. Update Your Website’s Nginx Configuration
Next, you need to update your Nginx .conf files to reference PHP 8.1 instead of PHP 7.4. This is a crucial step because Nginx relies on PHP-FPM to handle PHP requests.
Open the .conf file for your website, typically located in /etc/nginx/sites-available/:
sudo nano /etc/nginx/sites-available/your-website.conf
Look for lines that refer to PHP 7.4,
…. /var/run/php/php7.4-fpm.sock;
Replace 7.4 with 8.1
Make sure to update every instance where PHP 7.4 is mentioned in the configuration file.
3. Restart Nginx and PHP Services
After making the necessary changes, restart both the Nginx and PHP services to apply the changes.