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:
Next, I installed PHP and MySQL:
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.
Halfway down the first page are the lines
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
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