Some codes

Update (14th february 2013): If you are also interested in installing PHP along with nginx here is the tutorial.

Yesterday I received my Raspberry Pi. After some testing I decided to try if it was possible to install a webserver on the pi. The answer is yes! I chose nginx because of its low memory footprint and ease of management and configuration, however you should be able to install any other like Apache or lighttpd. I assume you have installed the Debian Squeeze distro in your memory card and that you are running the GUI at the moment of following this steps. Let’s start: Open a terminal and execute:

sudo apt-get install nginx
Wait for the process to finish and then we’ll check if www-data user is already created and also the www-data group:
sudo useradd www-data

If it says that is already created, don’t worry. We’ll continue to add the user to the group. We create the www-data group:

sudo groupadd www-data

Now we will add the www-data user to the www-data group:

sudo usermod -g www-data www-data

Now we’ll head to the nginx config file. Unless your raspberry pi has an ipv6 address assigned you’ll have to comment out the following line from /etc/nginx/sites-enabled/default : You have to add # at the beginning of the 10th line, so it looks like this:

# listen[::]:80 default ipv6only=on ##...

if you are a new come to the linux world and you feel lost, you can edit this file using this command:

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

And to exit and save press control + x. You’ll be prompted to confirm you want to save changes. Since our default config points to /var/www/ to search for our html files we’ll need to create that folder and assign the correct permissions and ownership:

cd /var/
sudo mkdir www
chown www-data:www-data www/

Now we’ve got our www folder created and ready to work with nginx. Let’s create an html to show the entire world we are here! inside /var/www

sudo nano index.html

Once we are in the editor:

<html>
Hello World!
</html>

We save it and we change the file ownership:

sudo chown www-data:www-data index.html

We’re ready to start our web server!

sudo service nginx start

Open a web browser in the raspberry pi and point to: 127.0.0.1 You’ll see the Hello World message appear! This is my first day with the pi, so, there are still many things to come and to do with it. I’ll publish here my testings and discoveries. Bye!

Photography: Emily Price