I decided to set up my Raspberry PI as a dedicated LAMP server. (LAMP is an acronym that stands for LinuxApacheMysqlPhp and are components required to run a Dynamic HTML webpage.).


All these components are Open Source ;


  • Apache is the webserver that will host my applications - for more information see http://www.apache.org/.
  • MySQL is "the world's most popular Open Source database" (their own claim !) - more information here http://www.mysql.com/
  • PHP is "a popular general-purpose scripting language that is especially suited to web development." (again their own claim !) - see http://php.net/



Before you start, it might be helpful to assign your Pi a fixed IP address - if you haven't done this already, see my post on how to do so at http://www.element14.com/community/docs/DOC-54237/l/static-ip-address-for-my-pi. You will need to know your Pi's address in order to access the server once you have installed it!The first step is to make sure the OS is up to date (good practice before making any PI upgrades) so I ran the following commands ;

  • sudo apt-get update
  • sudo apt-get upgrade


Step 1 - install Apache


Install using the following command;


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


Once that has completed, start the serber using the following command


  • sudo service apache2 restart


To test that the server is running, type your Pi's IP Address into the browser, and you should get a simple page displayed - e.g.


It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.


Although Apache is all working at this point, there are a few configuration changes you can make to improved this - see the 'More Infomation' section at the bottom of this page.



Step 2 - Install MySQL


Use the following cmannd to install the MySQL database


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


During the install a prompt will pop up asking you to supply a password for the database root user - enter something appropriate !


Once the install is complete, the database will be up and running. To test this use the following to get comand line access to the database


  • mysql -u root -p


You will be prompted for the root password that you assigned above. You can use this utility to run SQL commands to create users, table, etc.


If you want to use a MySQL client there are several free ones available - I use Heidi (see http://www.heidisql.com/). If you want to do this you will need to do the following steps


  • Configure MySQL to use the Pi's IP Address
  • Create a database user for you client PC


Configure MySQL


Edit file my.cnf in /etc/mysql - i.e


cd /etc/mysql sudo nano my.cnf          


Look for the entry bind-address and edit it to be the Pi's ip address - e.g.


bind-address            =          



Create a database user for your client PC


You need to use the SQL client on the Pi to add a user for your client PC. You will need to define a user and password - these will then be the credentials that you use in your SQL Client. In these examples I am using user root and password password - I suggest you choose something less obvious!


Use the following command on he Pi to open the MySQL client


  • mysql -u root -p            (You will need to supply the MySql root password when prompted)


Enter the following, substituting your own user and password values that you want to use - don't forget to surround the values with quotes and terminate with a semi colon.


CREATE USER 'root'@'' IDENTIFIED BY 'password';          


Note that in the above is the ip address of my client PC, not the Raspberry Pi !!


You will also probably want to create a database to use (MySql isn't much use without one !) - again you have to then assign privileges to your client in order to use it.

You might as well do this at this point, with the following sql commands on the Pi;


CREATE DATABASE petersdb; GRANT ALL PRIVILEGES ON 'petersdb'.* TO 'root'@'' IDENTIFIED BY 'password';         


(Again, don't forget the quotes and terminating semi-colons!)


Having done all the above you can now use an SQL client on your PC (e.g. Heidi - see http://www.heidisql.com/) to connect to the MySQL instance on the Pi - you will need to supply


  • The IP Address of the Pi
  • The user and Password that you specified in the CREATE USER command above


Once you have done this you will need to restart MySQL - either reboot the Pi, or use the following command


  • sudo service mysql restart


*Edit* - try using PhpMyAdmin !


If you want to make managing your database(s) at lot easier, try installing PhpMyAdmin. There's some really good instructions available at http://www.dingleberrypi.com/2012/09/tutorial-install-phpmyadmin-on-your-raspberry-pi/.


Step 3 - Install an FTP Server


Its very hard to utilise a web server effectively without being to put files on it! - so we need to install an FTP server. as follows


Change ownership of the web root, and then download the ftp server as follows. Note that if this is going to be a public facing server you need to create a new user and password to use - dont use the default pi/raspberry !!


  • sudo chown -R pi /var/www     (substitue the user you have cretaed for pi in this command)
  • sudo apt-get install vsftpd


Now we need to edit the conf file as follows.


  • sudo nano /etc/vsftpd.conf


Find and edit the following lines as specified:


  • Change anonymous_enable=YES to anonymous_enable=NO,
  • Uncomment local_enable=YES
  • Uncomment write_enable=YES
  • then go to the bottom of the file and add force_dot_files=YES


When you have done the above restart the FTP server using


  • sudo service vsftpd restart

Having done this you can now FTP to the PI use a free client such as FileZilla (see https://filezilla-project.org/


You will ned to supply the following values

  • IP Address of your Pi
  • User and Password - this is the pi user and password that you use to log on to the pi - e.g. pi and raspberry by default. If this is going to be a public facing server, change your password !!!!



More Information


  • Apache configuration

Apache will work 'out of the box' as installed above - however this is a default configuration, and you can tidy it up a bit.


If you restart Apache (using the command sudo service apache2 restart) you will see an error along the lines of Could not determine the server's fully qualified domain name, using 127.0.X.1 for ServerName.

This is because the Pi hasn't been set up as a named server. This can be done quite easily - all you need to do is decided on a name for your server, and to know your IP address.


For the following instructions I have chosen to call my pi lamppi - and my IP address is


N.B. To edit files use sudo nano filename - e.g. to edit file hostname in directory /etc;


cd /etc sudo nano hostname



Edit file hostname in directory /etc to contain the entry as below (using the name you have chosen for your server).



Edit file /etc/hosts as below. you need to


  • Add a localhost entry for your IP address (e.g. localhost)
  • Add an entry for your chosen server (e.g.    lamppi)
  • lamppi_2.png

Next, create an extra file servername.comf in the /etc/apache2/conf.d. You can use nano to create the file - i.e


  • cd /etc/apache2/confd
  • sudo nano servername.conf


Create an entry as shown below




You should now find that you can stop/restart apache without any errors being thrown.






Helpful commands


Restart MySQLsudo service mysql restart
Update OS
  • sudo apt-get update
  • sudo apt-get upgrade