Setting up a personal web server on the Raspberry PI


This week has been an awful week. I have basically had very limited access to the internet and so this has put me behind on the schedule that I had set for May.
I have therefore decided this week to finally type up the notes I had taken when setting up the Raspberry PI as a personal web server.

Why set up a Web Server on the Raspberry PI?

There are a few reasons why you might set up your Raspberry PI to run as a web server.
If you are a student learning to program then you might find it useful to run the Raspberry PI as a web server so that you can practice your PHP scripting or PERL scripting. PHP is good as it is a modern OO language that incorporates a lot of the principles of other programming languages
You can learn common techniques with PHP such as test driven development. There are also good coding frameworks available such as Codeigniter which will help you learn MVC. Skills learned in PHP can easily be transposed to other languages including C# and Java.
Other more hobbyist programmers might like a web server to run something like Joomla to create a home intranet site.
People who design WordPress templates might like a personal web server to test out new templates. By using the Raspberry PI as the web server the designer can use other computers to make sure the layout looks good in Internet Explorer, Chrome and Firefox.


This guide assumes you are using the default Raspbian Wheezy operating system.
The web server that is to be used is Lighttpd.
PHP will be installed as the scripting language.
MySQL will be installed as the database server.

Get your IP Address

If you are working directly on the Raspberry PI then you can skip this part but if you are accessing via SSH obtain the IP Address of the Raspberry PI by typing the following into a terminal window on the Raspberry PI.


This will return an IP address in the form of 192.168.1.x where x is the 4th number. (For example 30).

If you follow this guide direct from the PI then you can get away with using localhost instead of the IP address when specified later on in the guide and you can skip the SSH step below.


If you plan to SSH onto the Raspberry PI from within Windows run Putty.exe ( and type in the IP address into the Host Name box. Now click “Open”.

If you plan to SSH onto the Raspberry PI from within Linux open a terminal window and type SSH 192.168.1.x (where x is the last number).

Whether you are running from within Windows or Linux you will be asked for the username and password. You should enter “pi” as the user and the password you set up for the “pi” user when you installed Raspbian.

You should now be logged in via SSH.

Update your repositories

First of all run an apt-get update to make sure everything you need is available to download.

sudo apt-get update

Installing Lighttpd

There are quite a few guides on the internet for showing how to set up a web server. For the Raspberry PI I chose to install Lighttpd as it is light in nature and won’t use up too much of the Raspberry PI’s resources.
To install Lighttpd run the following command

sudo apt-get install lighttpd

To test whether the web server is installed correctly type the following into the web browser address bar:


Replace x with the last number of your IP address. If you are running directly on the Raspberry PI then you can just enter the following:


You should see a placeholder page as shown above.

Installing PHP

To install PHP run the following command:

sudo apt-get install php5-cgi


Now you need to add a line to the php.ini file. To do this there is a file called php.ini in /etc/php5/cgi.

Type the following:

sudo nano /etc/php5/cgi/php.ini

Navigate to the bottom of the file and add the following line.

= 1

To save the file press CTRL and O on the keyboard and to exit nano press CTRL and X.

Finally to get fast CGI working type the following onto the command line:

lighty-enable-mod fastcgi


Now type the following:

sudo lighty-enable-mod fastcgi-php 

Now the web server needs to be restarted.

/etc/init.d/lighttpd restart

Create a test PHP script

To test that PHP is installed correctly type the following into the terminal window:

sudo nano /var/www/phpinfo.php

Now within nano enter the following script:

<?php    phpinfo();?>

Press CTRL and O to save the file and CTRL and X to exit nano.

Within a web browser type the following into the address bar:


Replace x with the last number of your IP address. If you are running directly on the Raspberry PI then you can just enter the following:



Install MySQL

There are three applications that will be installed for MySQL:


  • MySQL-Server
  • MySQL-Client
  • PHPMyAdmin

MySQL-Server is the actual database server.
MySQL-Client enables you to interact with the server from the command line.
PHPMyAdmin enables you to interact with the server from within a web browser.

To install all three applications at once type the following into the terminal window:

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


During the install you will be asked to enter a password for the root user. Do not confuse this with the root user within Linux. This is the root password for the database server. Enter a strong password. Repeat the password when asked to do so.
During the installation of PHPMyAdmin you will be asked which web server is installed. Choose lighttpd.
A message will appear asking whether you want to create a dummy database. As the message states, if you know what you are going to be using the database server for or a database is already configured then you can answer no but if you are just experimenting then you can answer yes.
I recommend answering yes to this. It doesn’t do any harm.
You will now be asked to enter the root password and repeat it. Enter the root password you created earlier. (remember this is the database root password, not the linux root password).
When the install has finished restart the server by typing the following into the terminal:

sudo /etc/init.d/lighttpd restart

To test that the database server has been installed correctly open a browser window type the following into the address bar:


Replace x with the last number of your IP address. If you are running directly on the Raspberry PI then you can just enter the following:


Enter the username and password to log in.


This tutorial has shown how to set up the basic web server with PHP and MySQL
You might now want to try installing WordPress, Joomla, Codeigniter and Blueprint.
I will be following up this article with details of how to install the aforementioned items later this week. I will also show you how to access the web pages externally and how to set up a host name to replace the IP address.
If you have any problems using this guide or you have tips for other users feel free to add them to the comments section.
Thankyou for reading.


  1. When I try the go to 192.168.1.x I just get a 403 – Forbidden error.
    I have checked through all the commands and I can't find where I might have gone wrong.
    Has anyone else had this problem and an suggestions on what I should do?

  2. Which step in the tutorial is giving you the 403 error? Is it when trying to SSH onto the PI or when trying to view a page in a browser?

    If you are logged directly onto the PI (ie not using SSH) then replace the 192.168.1.x with localhost.

    If you are using SSH then the address you put in the browser is the same address you used to SSH onto the PI. (i.e, replace 30 with the number you get from running IFConfig)

  3. hi! very nice article! I was doing exactly that half a week ago and happen to follow your guide without knowing. Would you help me set up an public_html folder inside /home/pi/ and some kind of free Cpanel.

    no tutorial explain it easily. I'm still new to Linux. I love tutorial witch explain what is going on!

    Thx a lot again!
    10/10 😉

  4. Hi,

    Hope you might be able to help. I've followed your instructions to the letter but when installing the MySQL server I get about half the way through and it throws up this error-

    [FAIL] /etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full!

    Any ideas how to fix this problem? Once it's gone through the install process it comes up with this –

    An error occurred while installing the database:

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    Any help would be appreciated! Cheers

  5. Hello from Paris Gary,
    as an absolute beginner, thank you very much for this step-by-step tutorial.
    I do not know where I got it wrong but I'm having an error message while configuring phpmyadmin, saying " ERROR 1045 (2800) : Access denied for user 'root'@'localhost' (using password: YES ) ".
    I tried " retry " several times, then without knowing how, just came back to the Terminal window :/
    Now I don't even know how to get back to the configuration.
    Thank you for your help and time. Cheers.

  6. Hi. Great tutorial!

    Everything works, except phpmyadmin. If I enter "http://localhost/phpmyadmin&quot; in my browser, I get the error: 404 – Not Found.

    I tried it, using the IP address, on my PC and it gives the same error. If I enter "phpinfo.php" instead of "phpmyadmin" it displays the page that you indicated.

    Any help would be appreciated!

    • You need to add your web pages to the folder /var/www. It is likely that you won't have permissions to add files to that folder. You can get around this by opening a terminal as root or adding yourself to the group that does have permissions. (I think it is www-data)

  7. Hello,

    I would like to monitor a sensor and display and store the data in real time through a web server on the pi. I have some ideas but I'd like to draw upon the collected wisdom in the pi community.
    1 have a php program that gets the data from a sensor
    2 continuously add the data to a file/database
    3 display the graph on a web page

    Step 2 is a database the best thing here or can I just output to a file. If a database is best then which one, is MySQL overkill?

    Step 3 how do I do this most efficiently?

    Any advice before I embark on this would be much appreciated.

    Thank you,


  8. Hello Gary. As I mentioned in a reply below, congrats for a well done, accurate and professional tutorial. I finally have my web server working now thanks to your work (and have quickly made a copy of my SD!)

    Now to finish up so I can actually start developing my new website. I need your help getting WordPress installed now, as I am sure many other readers also do. I have chased the wrong rabbit again and again as I've tried various installation tutorials and it has further aged me. But alas, finally I discover you (a highly competent rabbit that can actually run in a straight line!).

    Pleeze provide us with the WordPress install (or at least refer us to a tutorial which works). Best regards and thanks much in advance!

  9. This is the 8th site I've used for tutorials on setting up a web server on the raspberry pi, and like all the others, this one doesn't work either. Does anyone know of a tutorial that actually works?

  10. hi guys! im having trouble with phpmyadmin i followed step by step until the options given for the web server to automatically configure i chose apache2 instead of lighttpd … its not working properly? any advice ? thank you in advance

  11. I have to agree with the article. Cost should not be the primary factor when one is looking for the best web host. However there are a plethora of web hosts out there who offer great wordpress hosting for a very competitive price. One thing to consider is page load times for the host.

  12. I was trying for 2 days to install WordPress by using nginx following all the tutorials on the internet, but I said to also try the lighttpd web server and your tutorial worked perfectly! Many thanks!

Leave a Reply