The FastCGI Process Manager (FPM) is an alternative to the FastCGI configuration with multiple enhancements. This is useful for high load websites. This tutorial will help you with the installation and configuration of PHP-FPM with Nginx on your Debian 10 Buster Linux system.
Prerequsities
You must have SSH access to the Debian 10 system with Sudo privileges.
Nginx Installation
Nginx packages are available under default repositories. SSH to your Debian 10 system with sudo privileges accounts and install the Nginx web server from the official repository.
sudo apt update sudo apt install nginx
PHP Installation
For the PHP installation we recommend to use Ondřej Surý‘s PPA, which provides latest PHP versions for Debian systems. Use the below couple of commands to add the PPA to your system.
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add - sudo echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list
Then install PHP latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages.
apt update sudo apt install php php-fpm
After installing the above packages php7.3-fpm service will automatically be started. You can make sure by typing below command on terminal.
sudo systemctl status php7.3-fpm ● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-12-03 10:01:54 UTC; 24min ago Docs: man:php-fpm7.3(8) Main PID: 9883 (php-fpm7.3) Status: "Processes active: 0, idle: 2, Requests: 3, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 3587) Memory: 14.2M CGroup: /system.slice/php7.3-fpm.service ├─9883 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf) ├─9884 php-fpm: pool www └─9885 php-fpm: pool www Dec 03 10:01:54 tecadmin-debian10 systemd[1]: Starting The PHP 7.3 FastCGI Process Manager... Dec 03 10:01:54 tecadmin-debian10 systemd[1]: Started The PHP 7.3 FastCGI Process Manager.
Nginx Configuration
Let’s create Nginx virtual host to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in a text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost.
sudo vim /etc/nginx/sites-available/example.com
Use the below basic Nginx Virtual host configuration with PHP FPM settings. Update the configuration as followings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | server { listen 80; root /var/www/html; index index.php index.html index.htm; server_name example.com; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; } } |
Save your changes to the configuration file and create a link to site enabled directory.
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
Then restart Nginx service to reload the changes.
sudo systemctl restart nginx.service
Test Setup
Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it.
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
Now access the info.php using server IP address (for default VirtualHost) for your configured domain in Nginx VirtualHost.
http://localhost/info.php
Conclusion
All done. You have successfully configured Nginx web server with PHP-FPM on your Debian 10 (Buster) Linux. Your server is ready to host websites.
3 Comments
The ppa:ondrej/php is used for Ubuntu, the article is about Debian.
ppa:ondrej/php is differently hosted than https://deb.sury.org. But both are maintained by the Ondřej Surý.
Hello Rahul,
Why do you recommend Ondřej Surý‘s PPA?
I checked it out and he said if you are using nginx, you are advise to add ppa:ondrej/nginx-mainline or ppa:ondrej/nginx
I’ll come back in a bit but please feel free to email me to say hi!