RADIUSdesk

logo

This is an old revision of the document!


Install Nginx

Prep

  • These instructions are for Raspberry Pi OS based on Debian version 12 (bookworm).
  • You can issue the command cat /etc/issue.net to confirm the version. It should say Debian GNU/Linux 12 .
  • Make sure it is up to date.
# Get the latest package lists
sudo apt-get update
# Update the system to the latest
sudo apt-get upgrade
  • Install Nginx
sudo apt-get -y install nginx
  • Ensure the web server starts up and is running
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
  • Navigate to the IP Address of the server where you installed Nginx using a browser to ensure Nginx serves content e.g. http://127.0.0.1

Configure Nginx to interpret .php files

  • The default install of Nginx does not support the serving of .php files.
  • We will install a program (actually a service) called php-fpm.
  • This service will listen for requests to interpret.
  • Install the php-fpm service by installing the default version 8.2 of the packages
sudo apt-get -y install php-fpm
sudo systemctl enable php8.2-fpm
sudo systemctl start php8.2-fpm

Modify Nginx

  • Now that the php-fpm service is installed we should change the default Nginx server to make use of it.
  • Edit the default server file:
sudo vi /etc/nginx/sites-enabled/default
  • Add index.php to this line:
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
  • Activate PHP processing by un-commenting this this section. Note that we use the UNIX socket and we are using 8.2 and not 7.4 which is specified originally in the config file.
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
}
  • Enable the hiding of .htaccess files
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}
  • Reload the Nginx web server's configuration
sudo systemctl reload nginx.service
  • Create a test .php file to confirm that it does work
sudo vi /var/www/html/test.php
  • Contents
<?php
    phpinfo();
?>