Home How to install PHP 7.1 on Debian 9
Post
Cancel

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.

1
2
3
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:

1
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:

1
2
3
4
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:

1
2
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
1
2
3
4
5
6
7
8
9
10
11
12
[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:

1
sudo systemctl restart php7.1-fpm