In this tutorial, we’ll set up Nginx web server along with PHP-FPM on MX Linux 23, which is based on Debian 12. So, let’s open the terminal and start by updating system first:
sudo apt update && sudo apt upgrade
Next, install Nginx web server by executing following command:
sudo apt install nginx
You may check the running status of Nginx by entering the following command:
sudo service nginx status
Then, install PHP-FPM (FastCGI Process Manager) in order to handle PHP scripts (Here, we are assuming that PHP 8.1 is already installed on the system – if not then see this article for installing PHP):
sudo apt install php8.1-fpm
Now, you may check the running status of PHP-FPM by entering the following command:
sudo service php8.1-fpm status
Next, we’ll configure the default location (/var/www/html) of the web server to serve the PHP scripts; so, let’s execute the following command in order to open default configuration file:
sudo nano /etc/nginx/sites-available/default
Then, amend the file as follows:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Save and exit nano by entering ctrl+o and then ctrl+x. Here, you can check whether Nginx configuration has been made correctly by entering following command:
sudo nginx -t
Now, restart the web server:
sudo service nginx restart
All set. Let’s create a PHP file in default location to check if everything works, but first change the access permissions of web server’s default location folder by entering following command:
sudo chmod -R 777 /var/www/html
Finally, create a PHP file that will be served from default location:
echo "<?php phpinfo(); ?>" >> /var/www/html/info.php
Now, enter the following URL into the browser and see the info.php gets rendered from web server’s default location.
http://localhost/info.php