Running an Nginx, PHP, and MySQL Webserver on the Raspberry Pi

For my project, I am going to be hosting a website on the Raspberry Pi. I want to be able to set the alarm on the alarm clock through the website and have the C++ program interact with the MySQL database to get alarm times. Many websites are hosted using Apache, but since Apache can be a bit of a resource hog, I decided to use Nginx. There are several articles out there that explain how to set up these services, but I had to jump between documents and I thought I would just put together a comprehensive guide. Undoubtedly, I’ll want to try this again in the future, and having it all written down will be handy.

I’m using the Debian package on my RPi, and supposedly the default Nginx Debian package is the wrong one. Here are the commands to install nginx:

echo "deb squeeze nginx" >nginx.list
echo "deb-src squeeze nginx" >> nginx.list
sudo mv nginx.list /etc/apt/sources.list.d
sudo apt-get update
sudo apt-get install nginx

Next, I installed PHP and MySQL:

sudo apt-get install mysql-server php5-cgi php5-mysql php5-fpm php5-cli

This installation will take a while. Note that when you are installing MySQL, you will be asked to enter a password for accessing MySQL with. You will need this password again in the future, so choose something you’ll remember! Or write it down.

The final step is to modify a configuration file.

sudo nano /etc/nginx/sites-available/default

Halfway down the first page are the lines

root /usr/share/nginx/www;
index index.html index.htm

The first line tells the server where the webpage files (.html, htm, php) are saved. The second line is a list of default index files, in order. Add index.php to the list so that the second line looks like

index index.php index.html index.htm

The server will first try index.php, then index.html, and finally index.htm when it tries to load the homepage. Next, scroll down a bit and find the section about the FastCGI server. Everything will be commented out, and we need to uncomment some lines. Additionally, we will add a small if-statement.


For more detail: Running an Nginx, PHP, and MySQL Webserver on the Raspberry Pi

About The Author

Scroll to Top
Read previous post:
Raspberry Pi Scoreboard
Raspberry Pi Scoreboard

This is a simple project that  tries to use the Raspberry Pi as a Scoreboard.. on a character LCD What...