How to install PHP 7.2 with EasyEngine

This article includes information about PHP 7.2 benefits and guides user how to install PHP 7.2 with easyengine and configure it their WordPress website.

About PHP 7.2

PHP 7.2 was officially released on November 30, 2017. The release has new features, functions, and improvements that will allow us to write better code. In this post, I will introduce some of the most interesting language features with PHP 7.2.
Some of the highlighted features are:

Core Improvements

Argument type declarations

Since PHP 5 we are allowed to specify in a function’s declaration the argument type that is expected to be passed. If the given value is of an incorrect type, then PHP throws an error.

Argument type declarations (also known as type hints) specify the type of a variable that is expected to be passed to a function or class method.

Object return type declarations

If argument type declarations specify the expected type for a function’s arguments, return type declarations specifies the expected type of the returning value.

Return type declarations specify the type of a variable that is expected to be returned by a function.

As of PHP 7.2 we are allowed to use return type declarations for the object data type.

Parameter Type Widening

PHP currently does not allow any variance of parameter types between child classes and their parent classes or interfaces.

Trailing commas in list syntax

A trailing comma after the last item in arrays is valid syntax in PHP, and sometimes it’s encouraged in order to easily append new items and avoid parse errors due to a missing comma. Since PHP 7.2 we are allowed to use trailing commas in grouped namespaces.

Security Improvements

Argon2 in password hash

Argon2 is a powerful hashing algorithm which was selected as the winner of 2015 Password Hashing Competition, and PHP 7.2 will bring it to us as a secure alternative to the Bcryptalgorithm.

Libsodium as part of PHP Core

Starting from version 7.2, PHP includes the Sodium library into the core. Libsodium is a cross-platform and cross-language library for encryption, decryption, signatures, password hashing and more.


Now, What Does PHP 7.2 Mean for WordPress Users?

According to the official WordPress Stats page, as of writing this, only 19.8% of WordPress users have upgraded to PHP 7.
Wordpress PHP Versions
You can see that a large majority of users, over 40%, are still running on PHP 5.6. What’s even scarier is that over 39% of users are using unsupported PHP versions. As of December 2016, WordPress.org actually bumped up their official recommendation for users from PHP 5.6 to PHP 7 or greater.
The numbers above are especially discouraging coming from a performance point of view, as PHP 7 has shown to be significantly faster.
However, according to various sources, PHP 7.2 is also slightly faster than 7.0.

Updating to PHP 7.2

So even I’m using Easy Engine for managing WordPress sites with Ngnix on some of my servers. It was high time for me to use PHP 7.2
As I like to keep things updated. Here’s a tutorial with regarding How to Install PHP 7.2 with EasyEngine.


All credits and thanks to VirtuBox.

Install php7.1-fpm and/or php7.2-fpm

On Debian 8 Jessie, add the deb sury repository before installing php7.x

apt-get install apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update

Then install the php release of your choice

 # php7.1-fpm
apt update && apt install php7.1-fpm php7.1-cli php7.1-zip php7.1-opcache php7.1-mysql php7.1-mcrypt php7.1-mbstring php7.1-json php7.1-intl \
php7.1-gd php7.1-curl php7.1-bz2 -y
# php7.2 fpm
apt update && apt install php7.2-fpm php7.2-xml php7.2-bz2  php7.2-zip php7.2-mysql  php7.2-intl php7.2-gd php7.2-curl php7.2-soap php7.2-mbstring -y

Configuration

Option 1) Using the preconfigured files available on our Github repository

To make the configuration of php7.1-fpm or php7.2-fpm easier, we have uploaded all our configuration files on Virtubox Github repository.
This way, you can download them directly from your server to use php7.1-fpm or php7.2-fpm.
To download our preconfigured files, use the following commands :

 # php7.1-fpm pool configuration
wget -O /etc/php/7.1/fpm/pool.d/www.conf https://raw.githubusercontent.com/VirtuBox/ubuntu-nginx-web-server/master/etc/php/7.1/fpm/pool.d/www.conf
service php7.1-fpm restart
# php7.2-fpm pool configuration
wget -O /etc/php/7.2/fpm/pool.d/www.conf https://raw.githubusercontent.com/VirtuBox/ubuntu-nginx-web-server/master/etc/php/7.2/fpm/pool.d/www.conf
service php7.2-fpm restart
# nginx upstream configuration 
wget -O /etc/nginx/conf.d/upstream.conf https://raw.githubusercontent.com/VirtuBox/ubuntu-nginx-web-server/master/etc/nginx/conf.d/upstream.conf
service nginx reload
# EasyEngine common nginx configurations
cd /etc/nginx/common
wget https://raw.githubusercontent.com/VirtuBox/ubuntu-nginx-web-server/master/common.zip
# if unzip isn't installed on your server
apt install unzip -y
unzip common.zip

Then to use php7.1-fpm or php7.2-fpm, follow the steps listed in the Configure your vhost with php7.1-fpm or php7.2-fpm


Option 2) Configure manually php7.1-fpm/php7.2-fpm

Copy the pool configuration from php7.0-fpm

# php7.1-fpm
cp -f /etc/php/7.0/fpm/pool.d/www.conf /etc/php/7.1/fpm/pool.d/www.conf

# php7.2-fpm
cp -f /etc/php/7.0/fpm/pool.d/www.conf /etc/php/7.2/fpm/pool.d/www.conf

Edit the listening port of php7.1-fpm or php7.2-fpm(for example, use 9080 instead of 9070)
Example for /etc/php/7.1/fpm/pool.d/www.conf

[www]
user = www-data
group = www-data
listen = 127.0.0.1:9080
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
ping.path = /ping
pm.status_path = /status
pm.max_requests = 500
request_terminate_timeout = 300

Example for /etc/php/7.2/fpm/pool.d/www.conf

[www]
user = www-data
group = www-data
listen = 127.0.0.1:9090
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
ping.path = /ping
pm.status_path = /status
pm.max_requests = 500
request_terminate_timeout = 300

Then restart php-fpm

# php7.1-fpm
service php7.1-fpm restart
# php7.2-fpm
service php7.2-fpm restart

Adding php7.1-fpm or php7.2-fpm

Option 1 : Replacing php7.0-fpm by php7.1-fpm/php7.2-fpm

In this case, you just have to edit the file /etc/nginx/conf.d/upstream.conf and to replace the port for the upstream php7.
So instead of server 127.0.0.1:9070; it will be server 127.0.0.1:9080; for php7.1-fpm or server 127.0.0.1:9090; for php7.2-fpm.
Reload Nginx to apply the configuration

nginx -t
service nginx reload
Option 2 : Running php7.1-fpm/php7.2-fpm in addition to php7.0-fpm

With EasyEngine, you can use a different php version for each website.
To add php7.1-fpm or php7.2-fpm in addition to php7.0-fpm, the first step is to add them in the upstream list.
Edit the file,/etc/nginx/conf.d/upstream.conf and add your new upstream :

# php7.1-fpm
upstream php71 {
server 127.0.0.1:9080;
# php7.2-fpm
upstream php72 {
server 127.0.0.1:9090;
}

Then to be able to use this new upstream, you have to make a copy of each php7.conf file located in /etc/nginx/common.
For example, for php7.1-fpm, you have to copy php7.conf into php71.conf, locations-php7.conf into locations-php71.conf etc …
And in each new .conf file, find and replace the line fastcgi_pass php7; by fastcgi_pass php71; for php7.1-fpm or fastcgi_pass php72; for php7.2-fpm.


Configure your vhost with php7.1-fpm or php7.2-fpm

To use php7.1-fpm or php7.2-fpm for your website, you just have to edit your vhost and to replace the configuration files used by EasyEngine.
You can edit your vhost directly with nano/vi/vim or with the command: ee site edit yourdomain.tld.
You will find the following lines at the end of your vhost configuration :

    include common/php7.conf;
    include common/wpcommon-php7.conf;
    include common/locations-php7.conf;

Just replace them with :

# for php7.1-fpm
    include common/php71.conf;
    include common/wpcommon-php71.conf;
    include common/locations-php71.conf;
# for php7.2-fpm
    include common/php72.conf;
    include common/wpcommon-php72.conf;
    include common/locations-php72.conf;

Just reload nginx to apply the new configuration.
That’s it you’re done. Enjoy the benefits of PHP 7.2 on your WordPress websites or any other custom installation.
Thanks for visiting.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x