03 September 2019
NGINX (pronounced engine x) is a popular lightweight web server application you can install on the Raspberry Pi to allow it to serve web pages.
In this tutorial we will investigate how we can use the Raspberry Pi to become a lightweight web server, by installing Nginx on it.
In an open Terminal session window, type the following command to install Nginx:
sudo apt-get update sudo apt-get install nginx
Once the installation has completed, you can start the Nginx service with:
sudo /etc/init.d/nginx start
You can now test that the Nginx web server is working as expected by starting up a local Chromium browser instance on your Raspberry Pi.
You should see the default nginx test page when you open
Now that Nginx is running, it’s another trivial package install to enable PHP support! In an open Terminal session
window, just type the following to install the latest
sudo apt-get install php-fpm
sudo nano /etc/nginx/sites-enabled/default
Find the following line:
index index.html index.htm;
index.php to the list:
index index.php index.html index.htm;
Then look for a section which is commented out (with
Reload Nginx to pick up the recent configuration changes:
sudo /etc/init.d/nginx reload
cd /var/www/html/ sudo mv index.nginx-debian.html index.php
Now open the
index.php file with
sudo nano index.php
Anywhere after the
<body> tag in the page, add the following:
<?php echo phpinfo(); ?>
Save and close up
nano. Now open a Chromium browser instance and navigate to
http://localhost. You should
see the familiar PHP info output.
Hopefully this was a simple walkthrough to show you how to setup the latest version of Nginx on the Raspberry Pi. As an additional bonus, I also included some easy steps to enable a fast and lightweight PHP connector for Nginx.