Updating PHP7-FPM on Ubuntu 20.04 for WordPress on nginx
A short guide on how to install and configure PHP 7.4 FPM on Ubuntu 20.04, allowing your WordPress installation running on Nginx to use a newer, more secure PHP version.
The following instructions assume you already have Nginx and WordPress installed.
Installation of the required PHP packages
Open the terminal and run the following commands to install PHP 7.4 and the extensions required by WordPress.
- Run this commands to install the PHP7.4
apt install -y php7.4 php7.4-cli php7.4-common php7.4-fpm
apt install -y php7.4-mysql php7.4-dom php7.4-simplexml php7.4-ssh2 php7.4-xml php7.4-xmlreader php7.4-curl php7.4-exif php7.4-ftp php7.4-gd php7.4-iconv php7.4-imagick php7.4-json php7.4-mbstring php7.4-posix php7.4-sockets php7.4-tokenizer
apt install -y php7.4-mysqli php7.4-pdo php7.4-sqlite3 php7.4-ctype php7.4-fileinfo php7.4-zip php7.4-exif
Edit the php.ini file
- Open the PHP-FPM configuration file in your favourite editor.
nano /etc/php/7.4/fpm/php.ini
- Locate the following setting and change its value from
1to0.
cgi.fix_pathinfo = 0
Don't forget to save the changes and close the editor.
Update the nginx configuration
Open your Nginx site configuration file, replacing {your config files} with the actual configuration filename.
- Open nano editor
nano /etc/nginx/sites-available/{your config files}
Locate the fastcgi_pass directive and update the PHP-FPM socket path
- Change
7.0to7.4.
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
This tells Nginx to pass PHP requests to the newly installed PHP 7.4 FPM service.
Restart PHP-FPM and Nginx
First, test the Nginx configuration to make sure there are no syntax errors. Then restart both services to apply the changes.
- Test the configuration and restart the services.
nginx -t
service nginx restart
service php7.4-fpm.service restart
That's it! Your WordPress installation should now be running through PHP 7.4 FPM instead of PHP 7.0.