How to Turn Your Raspberry Pi into a Fully Functional Web Server

Raspberry Pi

First we will start with the shopping list. You will need one of each of the required items. This list is assuming you already have a USB keyboard and USB mouse.

QTY Required Items Price(USD)*
1 Raspberry PI $35.00
1 Micro USB cable $5.79
1 SD Card (class 10, minimum 4GB recommended) $7.63
Total: $48.42
Optional Items
1 Power Supply $9.95
1 HDMI Cable $2.28
1 Case $12.75
1 Wireless Card $6.82
Total Including Optional Items: $80.25

*Prices are subject to change

After you’ve collected your hardware, you need to flash your operating system onto your SD Card. For this tutorial we will be using Raspian. I recommend it because it is an optimized version of Debian built specifically for Raspberry Pi’s. The last stable downloads can be found here.

To flash your SD Card, you will need to unzip the image and write it your SD card using Win32DiskImager. This tool can also be used to after our initial setup to create an image of our finalized implementation(very useful as a backup).


After the image is flashed, you can boot your device. At this point you can use your HDMI Cable/Mouse/Keyboard for your initial configuration, or you can use an SSH Client like Putty to connect. The default hostname, login, and password are as follows:

Username: pi
Password: raspberry

raspberry pi putty

For this tutorial, I will be using putty. On first boot, you will be prompted with a configuration tool called Raspi-Config. If the raspi-config doesnt load automatically, just enter the following command from the shell to get started.

sudo raspi-config


The settings I recommend you update are


The usual distribution images are 2 GB. When you copy the image to a larger SD card you have a portion of that card unused. expand_rootfs expands the initial image to expand to fill the rest of the SD card, giving you more space. By default, 64mb is reserved for the Graphical UI. Since we plan on using this as a web server, I reduce this to 32mb with the memory_split command.

After you finish your changes to the raspi-config, you should reboot your pi using the following command:

sudo shutdown -r now

At this point you have a fully functional linux server, but we still need to install apache, php, and mysql. This part is actually rather straightforward.

First, run the following commands from the shell to install Apache and PHP.

sudo apt-get update

sudo apt-get install apache2 php5 libapache2-mod-php5

The Locations of the Apache and PHP files are respectively



Next, run the following command to install MySQL.

sudo apt-get install mysql-server mysql-client php5-mysql

You will need to create a password for the MySQL Root Account

mysql root

After this is completed, give it a try! To test Apache, navigate to the IP or Hostname of your Rasberry Pi in your browser, and you should see the famous “It works!” Screen.

it works apache

To test the PHP, create a text file under your /var/www/ directory called phpinfo.php with the following contents:


Navigate to the file:


And that’s it! You’re done. You’ve got a fully functionally Raspberry Pi Web Server!

Some Extras:
For ease of use you might want to install an FTP Server. You have a few options PROFTP, VSFTP. I prefer VSFTP and that can be installed with the following commands:

sudo chown -R pi /var/www
sudo apt-get install vsftpd

The configuration file for vsftp can be found here:


If you are in a windows environment, you might find it useful to install SAMBA for network shares. To install samba, use the following commmands

sudo apt-get install samba

The configuration file for samba can be found here:


Raspberry PI Full Specs:
•Broadcom BCM2835 700MHz ARM1176JZFS processor with FPU and Videocore 4 GPU
•GPU provides Open GL ES 2.0, hardware-accelerated OpenVG, and 1080p30 H.264 high-profile decode
•GPU is capable of 1Gpixel/s, 1.5Gtexel/s or 24GFLOPs with texture filtering and DMA infrastructure
•512MB RAM
•Boots from SD card, running a version of the Linux operating system
•10/100 BaseT Ethernet socket
•HDMI video out socket
•2 x USB 2.0 sockets
•RCA composite video out socket
•SD card socket
•Powered from microUSB socket
•3.5mm audio out jack
•Size: 85.6 x 53.98 x 17mm”


  1. Thanks so much for this tutorial, am just about to start a project on the PI and found this very useful, i will however be installing ruby on rails as well.

  2. Great help! Thank you very much ^^

  3. I get a bit lost at this point:

    “To test the PHP, create a under your /var/www/ directory called phpinfo.php with the following contents:”


    “Navigate to the file:”

    How do I do these bits?

    • dconroy

      This was a typo! Thanks for pointing it out. It is meant to say create a text file called phpinfo.php and then browse to it from a web browser.

  4. James Miller

    Would it be able to host a very simple HTML or php website?
    I don’t know much about servers so I am unsure of the possibilities of using a raspberry Pi like this.

  5. Urgggh! This article was the final push for me to get into another “stuff”. This looks too much fun. Thanks for the post though.

    I just placed an order for my first Raspberry through Amazon. I am curious as to how responsive this server setup can be in real world though.

    Finially do I need a HDMI cable as you indicated in the shopping list? Can’t you just SSH into the hardware through Ethernet after you prep the SD card?

    • dconroy

      It’s optional! Good Catch, ill update the post. SSH works just fine! Good luck!

  6. Great article. I’ve done something similar, but I used a flat database instead of SQL. It seems to work quite well, my Pi is serving hundreds of pages a day.

  7. Thanks so much for the great tutorial! I was wondering if you know of a guide to setting up a website with the software we just installed. Things like adding a robots.txt, where to add the files for the pages, etc. Just getting into web server management thanks to my pi and this page.

  8. Worked perfectly for me Dave, excellent instructions, just what I was looking for…now set up and running with lots of ideas…..many thanks!

  9. Thank you so much for sharing. I have a problem after everything is done. I uploaded all the files, which included html, css, jpg, and php, to the raspberry pi through FTP. When I used both browsers, GoogleChorme and Firefox, to test it, the images and the style from css cannot be displayed. There is only text showing on the site. Could you tell me what the problem is?


  1. The Pi Emerges in Real Estate - [...] device between your Association Management System and other systems. David has an excellent description of setting up a…
  2. Week 7 | A New Kind Of Pi, A Raspberry Pi - [...] [...]
  3. Turn Your Raspberry Pi Into a WiFi Hotspot with Edimax Nano USB EW-7811Un (RTL8188CUS chipset) | - [...] because the Edimax was the first wireless adapter I ever recommended(turning a Raspberry Pi into a fully functional web…
  4. Using your Raspberry Pi as a Wireless Router and Web Server | - [...] about 100km from Seoul. They are working on a project where they are using Raspberry Pi’s as a web…

Leave a Reply

Your email address will not be published. Required fields are marked *