Raspberry Pi Webserver Using lighttpd

Install Components

Install lighttpd

sudo apt-get -y install lighttpd

Install PHP:

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

Install FastCGI to handle PHP pages:

sudo lighty-enable-mod fastcgi-php

Restart the lighttpd  service to apply everything;

sudo service lighttpd force-reload

Adjust Permissions

Make www-data  the new owner of the directory that serves up the Webpage:

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

Modify the permissions to make it writeable:

sudo chmod 775 /var/www

Add the pi user to the www-data  group:

sudo usermod -a -G www-data pi

Make a symlink in pi’s home directory for easy editing of the Webpage files:

cd ~
sudo ln -s /var/www www

Now you can edit the files from ~/www  instead of going to /var/www .

Test Functionality

The default page should now be accessible on the local network by navigating to the Pi’s IP address.  Navigate to the Pi’s IP address in a browser from another device on the network.

Backup the default page and replace it with your own:

mv /var/www/index.lighttpd.html /var/www/index.lighttpd.orig

Add the following code to the file and save it as index.php :

<title>Lighttpd and PHP Installation</title>
<h1>Test Results</h1>
<p>Lighttpd is working.</p>
<p><?php phpinfo();?></p>

From here, you can create your own pages.  The code above just gives you a good starting point to make certain everything is working as it should be.

Modify the port on which the page can be accessed

Edit the lighttpd  config file

sudo vi /etc/lighttpd/lighttpd.conf

Modify the following line to change the default port (80):

server.port  = 8080

Save the file and restart the server

sudo /etc/init.d/lighttpd restart

Now you can access the Pi using your custom port:


Access By Name Instead of IP Address

Accessing the Website will be easier if you can enter a name instead of remembering the IP address.  For this, we will use Bonjour to assign the .local domain.  Install it and reboot:

sudo apt-get install avahi-daemon
sudo reboot

Now you will be able to access your Pi’s Webpage by entering


(or whatever you renamed it to) in a Web browser.


Leave a Reply