Installing Nginx, PHP5 and SQLite3 on a Raspberry Pi

If you have a Raspberry Pi then you are probably going to run a web server on it. You have a couple of options, but I found that Nginx runs like a charm and is super easy to setup. If all you want is to serve up static files then you can wrap up there. But considering you have a Raspberry Pi, you probably also have some interesting projects that will require dynamic pages and probably a database. Enter PHP and SQLite.

Follow these steps to get your environment up and running in no time.

Nginx

The first thing you want to do is make sure the apt-get repositories are updated and everything already installed is upgraded to the latest version. So run line below first, it may take a while depending on your Internet speed and how many upgrades are needed.

Now install Nginx with:

Remember to answer yes when it asks you if you want to install the program.

Check that the server was installed properly by first starting the server and then in a browser type in the address of your Raspberry Pi, http://<address_of_your_rpi>.

The default setting is that the server will look for content in the folder /usr/share/nginx/www. But you might want to change it to a more conventional location, such as /var/www. This folder doesn’t exist yet, so create it with:

The server isn’t setup to look in this folder yet. You will first need to create a new site configuration in the sites-available folder.

Open up the file and add the following lines into the file.

The server still isn’t using the new settings yet.

Ok, now your Nginx server is setup to server static files from the folder /var/www. Try it out by placing a html file in the folder and writing down the address in a browser.

Want more information on you to configure the Nginx server? Check our their wiki. Do you want to make your server more secure? Here are some tips.

PHP5

Next install PHP5 with the following commands:

Nginx isn’t configured properly to use PHP5 yet. Go back to your server file created in the previous step and make the following updates.

Save the file and restart nginx.

Test that everything is working by creating a file called test.php with the following content.

Point your browser at http://<address_of_your_rpi>/test.php  and you should get a page that looks like this:

Screen Shot 2014-01-19 at 7.05.32 PM

 SQLite3

Install SQLite3 and the PHP5 module with:

Remember this is SQLite3 not SQLite2! There’s a difference. Below is some code you can run to test that SQLite3 is installed and working with PHP5.

As a side note. If you want to install SQLite3 on OS X (I’ve tested on 10.8.5) then download the binary from: http://www.sqlite.org/download.html

Download and unzip the the file ‘sqlite-shell-osx-x86-XXXXXXX.zip’, where X is for the latest version.

Move the sqlite3 binary file to /usr/bin/.

Stay tuned for more.