Development

How to install PHP 7.1 on Debian 9

In this article, we will discuss the installation of PHP 7.1 on the Debian 9 to meet your needs.

PHP 7.1 is not available via the default Debian repositories, so we will add the “packages.sury.org/php” repository, update the system and install the PHP 7.1 packages.

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update

To install PHP 7.1 and necessary modules:

sudo apt install php7.1-common php7.1-readline php7.1-fpm php7.1-cli php7.1-gd php7.1-mysql php7.1-mcrypt php7.1-curl php7.1-mbstring php7.1-opcache php7.1-json php7.1-zip php7.1-xml 

Change default PHP settings:

sudo sed -i "s/memory_limit = .*/memory_limit = 256M/" /etc/php/7.1/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.1/fpm/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.1/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.1/fpm/php.ini

PHP-fpm process manager has three choices: Static, Dynamic and Ondemand. The default setting for the process manager is “dynamic”, we will change it to “ondemand”.
Rename the default FPM  pool configuration file and create a new one:

sudo mv /etc/php/7.1/fpm/pool.d/www.conf /etc/php/7.1/fpm/pool.d/www.conf.org
sudo nano /etc/php/7.1/fpm/pool.d/www.conf

/etc/php/7.1/fpm/pool.d/www.conf
[www]
user = www-data
group = www-data
listen = /run/php/php7.1-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Save and exit.

Restart PHP-fpm:

sudo systemctl restart php7.1-fpm

 

 

We will be happy to hear your thoughts

Leave a reply