How To Update to PHP 7.4 Ubuntu 16.04 Drupal 7 Nginx

| Servers | 187 seen

I was facing problems with some Drupal modules not being supported, before upgrading to PHP 7.4 version.  

As I had running Ubuntu 16.04 server with Nginx and PHP 7.0 FPM on in I felt a bit afraid performing a live update and decided to make a new backup for all settings. 

Here I found some good advice: How To Install PHP 7.4 on Ubuntu 20.04/18.04/16.04

and also for Drupal specific things took my own advice from here: How to Install Drupal with Nginx, PHP-FPM 7.4, MySQL, phpMyAdmin on Ubuntu 20.04 - Linode Guide

Install PHP 7.4 on Ubuntu 18.04/16.04

Step 1: Add PHP PPA Repository

We’ll add ppa:ondrej/php PPA repository which has the latest build packages of PHP.

sudo apt-get update

sudo apt -y install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

Step 2: Install PHP 7.4 on Ubuntu 18.04/19.04/16.04

Install PHP 7.4 on Ubuntu 18.04/19.04/16.04 using the command:

sudo apt -y install php7.4

Check version installed:

$ php -v

Install  PHP-FPM

Next, install php7.4-fpm with php-gd extension that is required by Drupal core:

sudo apt-get install php7.4-fpm php7.4-cli php7.4-gd php7.4-mysql php7.4-xml -y

Configure Nginx and PHP-FPM

In this step, we will configure Nginx to use php-fpm to serve HTTP requests for PHP pages. Go to the php-fpm directory "/etc/php/7.4/fpm" and edit the "php.ini" file:

sudo nano /etc/php/7.4/fpm/php.ini

Un-comment the cgi.fix_pathinfo line and change the value to "0"

When using nano command you can use CTRL+W to locate that line. Once changed press CTRL+O to save changes and CTRL+X to exit from nano editor

Now we should modify the default Nginx virtual host configuration. Edit the "default" file and enable the php-fpm directive.

sudo nano /etc/nginx/sites-available/reinisfischer.com

Un-comment  location ~ \.php$ section, so it look like this

location ~ \.php$ {

include snippets/fastcgi-php.conf;

# With php7.4-cgi alone:

#fastcgi_pass 127.0.0.1:9000;

# With php7.4-fpm:

fastcgi_pass unix:/run/php/php7.4-fpm.sock;

}

CTRL+O and CTRL+X

Then test the Nginx configuration with the command "nginx -t" to ensure that it is valid:

nginx -t

If there is no error, restart nginx and the php-fpm service:

systemctl restart nginx

systemctl restart php7.4-fpm

That's it! Hope it helps!

Add new comment