Digity Republic

Tech News, Reviews, Deals, and How-To's

Install PHP 7.3 and the necessary PHP extensions on an Ubuntu Nginx server for WordPress.

Install PHP

image og PHP

Install PHP: This post will lead you through the process of setting up PHP 7.3 on your Ubuntu Nginx server, as well as installing the essential and recommended PHP Extensions for the WordPress website. PHP versions 7.1 and older are approaching the end of life (EOL), so if you haven’t done so already, it’s time.

I’m using a machine that is already set up and running PHP 7.2 to write this post.

The instructions in this post presume the following before you start.

  • You are using Ubuntu 16.04 or 18.04 at the moment.
  • You have access to sudo or root.
  • Nginx is using your server.

Install PHP: Update package lists and add PPA repositories.

To add the PPA:ondrej/PHP PPA repository to your system and refresh the list of available packages, do the following instructions. Despite the fact that there are other potential sources for these packages, I recommend this PPA since it includes the most recent PHP packages and extensions for Ubuntu systems.

sudo add-apt-repository ppa:ondrej/php
sudo apt update

After doing this, which should only take a minute, you may install and configure the new PHP package and any necessary extensions.

Install PHP 7.3 and any necessary extensions.

The subsequent instructions will install PHP 7.3 on your computer together with the essential and suggested extensions for utilizing the most recent core branch of WordPress.

php-7.3 and php-7.3-fpm installation;

sudo apt install php7.3 php7.3-fpm

Run the following tests to make sure you have all of the necessary and advise extensions for operating WordPress websites (these extensions ought to be adequate for most other PHP-based CMS systems or functionalities).

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 php7.3-tokenizer 

A list of the PHP extensions for WordPress that are necessary and advised:

In the WordPress Server Environment Documentation, which is fully accessible by clicking here, WordPress has a list of the required and recommended PHP extensions for running WordPress optimally. For your convenience, the list as of December 18th, 2019, is provided below, with WordPress version 5.3.1 being the most recent and PHP 7.3 being the recommended version. Since many of them are already included in the php7.3-common package, the prior instructions did not explicitly add them.

necessary extensions;

curl –operates on remote request requests.
dom – used to automatically configure IIS7+ and to evaluate Text Widget content.
exif – uses picture information that is saved there.
fileinfo –used to determine the mime type of uploaded files.
hash – passwords and update packages are used for hashing.
JSON – used for server-to-server communication.
mastering – used to manage UTF8 text appropriately.
MySQL – connects to MySQL to communicate with databases.
libsodium – offers securely random bytes and validates signatures.
OpenSSL – enables connections to other servers via SSL.
pcre – improves the efficiency of code searches when matching patterns.
imagick – improved image quality is provided for media uploads. For further information, see WP Image Editor is coming! When Ghost Script is also accessible, smarter picture scaling (for smaller images) and PDF thumbnail support will support.
XML – used to parse XML, for example from a third-party website.
zip – used to unzip packages including WordPress updates, theme, and plugin files.

Install PHP: extension suggestions;

filter – utilized to safely filter user input.
gd – The GD Graphics Library using as a functionally constrained fallback for image modification if Imagick is not present.
iconv – used while changing character sets.
mcrypt – When libsodium and /dev/urandom are unavailable, generates random bytes.
SimpleXML – use to parse XML.
xmlreader – use while processing XML.
zlib – Compression and decompression using Gzip.

Adjust your Nginx setup to include PHP 7.3.

If you previously have an older PHP version installed and configured, upgrading your site’s Nginx settings to accommodate the freshly installed PHP 7.3 will only need altering a small portion of the configuration code.

You will need to alter the default configuration at /etc/nginx/sites-available/default if you are using the default site block and only running one site on the service, which would place your site’s document root at /var/www/Html/. To accomplish this, use the command below.

sudo nano /etc/nginx/sites-available/default

Edit the relevant configuration file in the same directory as the “default” file, or if you’re using a specially built site block, wherever your sites’ configuration may set up if you have multiple sites and configurations and want to apply PHP 7.3 to each one separately rather than making it the default.

To set up the file for usage with PHP 7.3, add or modify the following code in the server configuration section after you have the file open in nano (or your preferred editor).

location ~ \.php$ { 
include snippets/fastcgi-php.conf; 
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; 

After that, don’t forget to restart php7.3-fpm and verify Nginx’s settings for issues before restarting or reloading Nginx. Until this accomplish, the adjustments will not effective.
sudo system restart php7.3-fpm is the command to restart it.
Use the command sudo nginx -t to verify that the changes to Nginx’s settings have been done appropriately.

sudo systemctl restart php7.3-fpm

Use the following commands to restart or reload Nginx if the configuration test for Nginx results in success:

sudo systemctl restart nginx
sudo systemctl reload nginx

To ensure that these services successfully resumed on your server, you can also execute the following command to verify their status. Following this, PHP 7.3 will operating any websites for which it was set up;

sudo systemctl status php7.3-fpm nginx

Frequently Asked Questions:

Where can I get PHP extensions to download?

The PHP Extension Communities Libraries (PECL) is a source for PHP Extensions that offers hosting services for PHP extension development and a list of all known extensions.

How do PHP extensions work?

image outcome
A PHP extension is a custom-design plug-in or library that offers a feature that numerous programs may utilize.

How can I determine whether the PHP extension is installed?

The list of modules will be the same wherever you execute this PHP command if your server has only one version of PHP installed. We shall use the generic command PHP -m. You may use this command to view a complete list of installed PHP modules and extensions.

Do You Need More Help?

Visit our forum, describe your question briefly and get answers