Setting up a Raspberry Pi Webserver

We will be setting up a simple webserver on the Raspberry Pi. In this tutorial it will just be set up to server over a LAN and not to the World Wide Web. This can be used to serve files such has music or movies across your network.

Update Raspbian

As usual, we'll want to make sure our system is up to date.

sudo apt-get update

sudo apt-get upgrade

Install Apache

sudo apt-get install apache2

Now let's restart apache.

sudo service apache2 restart

Verify your server is running

sudo service apache2 status

You should get back a message similiar to 'Apache2 is running (pid 1234)'

Determine your RPi's IP address

ifconfig

Copy or write down the IP address after 'inet addr' in the 'Ethernet' or 'eth0' block

Visit your new server site

Open a browser on your laptop or desktop computer (on the same network) and enter your Pi's IP address. (for example mine is http://192.168.1.6) The default apache 'It Works!' test page should display.

Boom! You did it! That sucker is running and it's yours! :)

The 'www' folder

The www folder is the main folder for your server. Anything you put in that folder will be accessable from your new server site. The 'It works!' page is the index.html file in your www folder. You can delete this page and create our own.

Create shortcut for your 'www' folder

ln -s /var/www/ ~/www

Setup FTP

We'll want to set up FTP (File Transfer Protocol) so we can transfer our favorite files (music, movies, etc) to the Pi from our desktop/laptop.

sudo chown -R pi /var/www

sudo apt-get install vsftpd

Locate the vsftpd.conf file from your home directory, type..

cd /etc

Open the vsftpd.conf file and make some modifications.

sudo nano vsftpd.conf

Remove the hashtag infront of 'localenable=YES' and 'writeenable=YES'

Switch 'anonymous_enable' to NO

Add 'forcedotfiles=YES'

control + x, then Y

sudo service vsftpd restart

SFTP also works

Raspbian comes with SFTP out of the box. So that might be a better solution.

SFTP is more secure because it piggy backs on SSH. It also uses a different port (22).

(but use your IP address)

You're done.

Now you have a webserver that will serve static files. Below you'll see that I'm using mine to serve up a movie file.

Your site doesn't have to be so plain jane, dress it up. Maybe make it something cool to use from within our home... hometainment?

Adjusting apache2.conf for the RPi

If you are going to be using your webserver in a way that will push the limits of the RPi, you should make some adjustments to the apache2.conf file. This is important because if you run out of RAM and then swap, your RPi will crash. Multiple people watching movies from the RPi will do this quick!

Locate /etc/apache2/apache2.conf

sudo nano apache2.conf

Once in the file, locate the 'prefork' section and observe the number values already set up. We'll want to change these values to better suit the RPi. Here is a great source to figure out the best fit.

For example, I used the following values for my RPi:

StartServers 1

MinSpareServers 3

MaxSpareServers 6

MaxClients 20

MaxRequestsPerChild 300

Save, exit and restart your server.

If you have questions or suggestions for another topic, comment below!