How To Setup A Web Server On Your Raspberry Pi

This page aims to summarise the steps required to install a webserver with PHP support onto your Raspberry Pi. This will allow the Pi to server HTML and PHP pages to users on the same network. This is a useful mechanism to view images and/or data on the Pi from another device, whether that is a PC, laptop, tablet or mobile phone.

How To Setup A Web Server On Your Raspberry Pi

Note : Before experimenting with network enabled features you should really make sure you have changed your Pi password from the “raspberry” default.

How To Setup A Web Server On Your Raspberry Pi

Step 1 – Install Lighttpd

Lighttpd is a lightweight web server application that works well on the Pi. It can be installed using the following commands :

sudo apt-get update
sudo apt-get -y install lighttpd

Step 2 – Install PHP

Next we need to install PHP. The order in which php5-common, php5-cgi and php5 are installed is important so don’t change their ordering in the line below :

sudo apt-get -y install php5-common php5-cgi php5

Then enable the Fastcgi module which will handle the PHP pages :

sudo lighty-enable-mod fastcgi-php

Once these packages are installed we can restart the Lighttpd service to pick up the changes :

sudo service lighttpd force-reload

Step 3 – Testing

In order to test your new webserver you need to know the IP address your Pi has on your network. To do this run this command :

sudo ip addr show

You will see a bloc

k of infor


ation similar to this :

1: lo: <LOOPB

How To Setup A Web Server On Your Raspberry Pi

ACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
    state UP qlen 1000
    link/ether b1:11:ab:42:24:2c brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0

The IP address in this example is Take this IP address and enter it into the address bar of a web browser on another device.

If everything has worked you should see the default Lighttpd “Placeholder” web page. It’s not very exciting but it is easy to replace with your own page.


For more detail: How To Setup A Web Server On Your Raspberry Pi

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top