With PHP versions 7.1 or older reaching end of life (EOL), f you haven’t already its time that you install and configure PHP 7.3 and any required extensions, this article will walk you through the process of setting up PHP 7.3 on your Ubuntu Nginx server, as well as installing the required and recommended PHP Extensions for WordPress website.
In this article I am working on a system that was already configured and running PHP 7.2.
Before you begin, the steps in this article assume the following
- You are running either Ubuntu 16.04 or 18.04
- You have sudo or root access
- Your server runs Nginx.
1. Add PPA repository and update package lists.
Run the following commands to add the ppa:ondrej/php PPA repository to your system and update the available package list. This PPA contains the latest PHP packages and extensions for Ubuntu systems and is my recommended choice, even though there are a number of possible sources for these packages.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
This should only take a minute to complete, after which you can install and configure the new PHP package and any required extensions.
2. Install PHP 7.3 and any extensions that you need.
The next commands will install php 7.3 to your system and both the required and recommended extensions for running a WordPress website using the latest core branch.
To install php-7.3 and php7.3-fpm;
sudo apt install php7.3 php7.3-fpm
To ensure that you have all of the required & recommended extensions for running WordPress websites (these extensions should also be sufficient for most other PHP based CMS platforms or functions), run the following;
sudo apt install php7.3-common php7.3-mysql php7.3-curl php7.3-json php7.3-mbstring php7.3-xml php7.3-zip php7.3-gd php7.3-soap php7.3-ssh2
A list of the required and recommended PHP extensions for WordPress
WordPress have a list of the required and recommended PHP extensions for running WordPress optimally in the WordPress Server Environment Documentation which is available in full by clicking here, but for your reference, below is the list as of December 18th 2019, with WordPress version 5.3.1 being the latest and PHP 7.3 being the recommended version. Many of them are included in the php7.3-common package, which is why they havent been explicitly added in the earlier commands.
curl – Performs remote request operations.
dom – Used to validate Text Widget content and to automatically configuring IIS7+.
exif – Works with metadata stored in images.
fileinfo – Used to detect mimetype of file uploads.
hash – Used for hashing, including passwords and update packages.
json – Used for communications with other servers.
mbstring – Used to properly handle UTF8 text.
mysqli – Connects to MySQL for database interactions.
libsodium – Validates Signatures and provides securely random bytes.
openssl – Permits SSL-based connections to other hosts.
pcre – Increases performance of pattern matching in code searches.
imagick – Provides better image quality for media uploads. See WP_Image_Editor is incoming! for details. Smarter image resizing (for smaller images) and PDF thumbnail support, when Ghost Script is also available.
xml – Used for XML parsing, such as from a third-party site.
zip – Used for decompressing Plugins, Themes, and WordPress update packages.
filter – Used for securely filtering user input.
gd – If Imagick isn’t installed, the GD Graphics Library is used as a functionally limited fallback for image manipulation.
iconv – Used to convert between character sets.
mcrypt – Generates random bytes when libsodium and /dev/urandom aren’t available.
simplexml – Used for XML parsing.
xmlreader – Used for XML parsing.
zlib – Gzip compression and decompression.
3. Configure PHP 7.3 in your Nginx configuration.
Next, you will need to update your sites Nginx configuration to accomodate the recently installed PHP 7.3, if you already had an older php version installed and configured, this will just involve updating a little bit of code within your Nginx configuration.
If you are using the default site block and only running a single site on the service, which would put your sites document root at
/var/www/html/ then you will need to edit the default configuration at
/etc/nginx/sites-available/default which you can do by issuing the following command.
sudo nano /etc/nginx/sites-available/default
If you have multiple sites and configurations, and want to apply PHP 7.3 to them individually instead of adding it as the default, then edit the appropriate configuration file within the same directory as the “default” file, or if you are using a custom built site block, wherever your sites configuration may be set up.
Once you have the file open in nano (or your choice of editor), then add or amend the following code within the server configuration section to configure it for use with PHP 7.3.
sudo systemctl restart php7.3-fpmTo check that the Nginx configuration changes have been made correctly –
sudo nginx -t
If the Nginx configuration test comes back as OK, then you can restart or reload Nginx using the following commands;
sudo systemctl restart nginx
sudo systemctl reload nginx
You can check the status of these service also by running the following command to make sure they successfully restarted on your server. After doing this, PHP 7.3 will be running any sites it was configured for;
sudo systemctl status php7.3-fpm nginx