How to Make a Raspberry Pi Web Server

Seven Parts:Start the Raspberry Pi Operating SystemRun Software UpdatesKeep the Firmware Up To DateSet Up SSHInstalling The Web ServerInstall MySQLInstall FTP

If you are looking for a way to make a cheap web server, primarily to be used as a testing environment or to store files, then the Raspberry Pi is perfect for you. What is a Raspberry Pi? It is an inexpensive mini computer, perfect for basic functions. This guide will show you how to take a new Raspberry Pi and turn it in to a web server. Please note that for this article, we will be working in Windows.

Part 1
Start the Raspberry Pi Operating System

  1. 1
    Obtain a copy of the Raspberry Pi OS (Operating System) from the link in the sources section. There are a few different distributions available, but for this article, we will be using the "Raspbian" version.
  2. 2
    Extract the image to the SD card. To do this, we need a tool called the Win32 Disc Imager. A link for this is also available in the sources section. Now open the tool, navigate to the drive letter that your SD card is in, select the location of the Raspberry Pi OS image, and select burn.
  3. 3
    Once done burning, you can place the SD card into your Raspberry Pi, then plug in the rest of the cords, being sure to plug in the mini USB last.
  4. 4
    Once the operating system finishes loading, you will need to log in. The default username is "pi", and the default password is "raspberry".
  5. 5
    Start by changing the password. From the command line type:
     passwd pi 
  6. 6
    Enter your new password and then confirm it. Please note, the cursor will not move when typing passwords but you are entering text.

Part 2
Run Software Updates

  1. 1
    Because you are running a fresh version of Debian, you will need to do some housecleaning, updating, and installing. First, we are going to update the clock, update our sources, then upgrade any pre-installed packages. Type the following at the command line (press return/enter after each line):
     sudo dpkg-reconfigure tzdata sudo apt-get update sudo apt-get upgrade 
  2. 2
    Set the date and time. From the command line type (replace parts as necessary):
     sudo date --set="30 December 2013 10:00:00" 

Part 3
Keep the Firmware Up To Date

  1. 1
    Next, we want to install Hexxeh's RPI update tool to help keep Raspberry Pi up to date. To do this, run the following commands (press return/enter after each line):
     sudo apt-get install ca-certificates sudo apt-get install git-core sudo wget -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update sudo rpi-update sudo shutdown -r now 

Part 4
Set Up SSH

  1. 1
    Now, we are going to set up SSH so that we can do everything else from a different computer. To do this, first note the I.P. address of the Raspberry Pi:

    You should see something like this:
     eth0 Link encap:Ethernet HWaddr fe:fd:45:xx:xx:xx inet Mask: inet6 addr: fe80::fcfd:xxx:xxx:xxx/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:35463998 errors:0 dropped:0 overruns:0 frame:0 TX packets:30563995 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:11300336376 (11.3 GB) TX bytes:33179556297 (33.1 GB) Interrupt:76 Make sure you are connected to internet!! The tag eth0 will appear if you have ethernet plugged in. Wireless might be wlan0, but could differ. 

    On the second line "inet" is the IP address of your Raspberry Pi.
  2. 2
    Now enable SSH and reboot (press return/enter after each line):

     After noting the inet addr use: sudo /etc/init.d/ssh start for every time you boot up the pi. Hint: If an error occurs, use the command below, and then the command up above. sudo apt-get install ssh Then, restart your pi: sudo shutdown -r now 
  3. 3
    You can now unplug the cords for your USB keyboard and your monitor. These are no longer necessary, as everything else will be done over SSH.
  4. 4
    Download an SSH client like PuTTy ( which can be downloaded for free from Google and connect to the IP address of your Raspberry Pi logging in with the username "pi" and the password you set earlier.

Part 5
Installing The Web Server

  1. 1
    To install Apache and PHP, execute the following commands:
     sudo apt-get install apache2 php5 libapache2-mod-php5 
  2. 2
    Now restart the service:
     sudo service apache2 restart 

     sudo /etc/init.d/apache2 restart 
  3. 3
    Enter the I.P. address of your Raspberry Pi into your web browser. You should see a simple page that says "It Works!"

Part 6
Install MySQL

  1. 1
    To install MySQL, install a few packages with the following command:
     sudo apt-get install mysql-server mysql-client php5-mysql 

Part 7
Install FTP

  1. 1
    We will now install FTP to allow transferring files to and from your Raspberry Pi.
  2. 2
    Take ownership of the web root:
     sudo chown -R pi /var/www 
  3. 3
    Next, install vsftpd:
     sudo apt-get install vsftpd 
  4. 4
    Edit your vsftpd.conf file:
     sudo nano /etc/vsftpd.conf 
  5. 5
    Make the following changes:
    • anonymous_enable=YES to anonymous_enable=NO
    • Uncomment local_enable=YES and write_enable=YES by deleting the # symbol in front of each line
    • then go to the bottom of the file and add force_dot_files=YES.
  6. 6
    Now save and exit the file by pressing CTRL-O, CTRL-X.
  7. 7
    Now restart vsftpd:
     sudo service vsftpd restart 
  8. 8
    Create a shortcut from the Pi user's home folder to /var/www:
     ln -s /var/www/ ~/www 
  9. 9
    You can now FTP using the Pi user and access the /var/www folder via a shortcut that should appear on login.


  • It's not necessary to install an FTP server if you have the SSH server installed. You can use an application such as WinSCP to connect via SCP which is safer and prevents the need to open up another port on your Raspberry Pi.
  • If you get an error message saying: "wget: command not found", run "sudo apt-get install wget"

Things You'll Need

  • Raspberry Pi (model B)
  • Blank SD card that is at least four gigabytes
  • Micro USB cable (for power)
  • Network cable with access to the internet
  • USB keyboard

Sources and Citations

Article Info

Categories: Web Programming