Turning your RPi into a powerfull (well… maybe not so) webserver.

I blame the Swedish Hollywood Wifes

One night when the rest of the family was watching a brain dead TV show called “Svenska Hollywoodfruar” I decided to see if I could get one of my Pi’s to work as a LAMP server. I have an RPi unit sitting on top of our file server that is just for that purpose, testing new things and seeing what it can do and can’t do. I was pretty sure that it could do what I wanted it to do but with some penalty in performance.

Said and done, these are the steps for turning your Pi into a LAMP server. I know there are many other tutorials and tips on how to do this. This article is just my take on it. Before we start let’s just drop into su mode.

> sudo su

Installing MySQL

Well obviously we need MySQL installed. It’s simple and goes like this:

> apt-get install mysql-server mysql-client

That will install the MySQL portion of our LAMP server. You will be asked to type in a password for the MySQL root user. I only used the MySQL root user in my tests so I recommend you to specify this when prompted.

Installing Apache2

The Apache2 server is equally easy to install, you just type in:

> apt-get install apache2

When the installation is done you can test it by directing a browser window to you RPi which was on my system and it should give you something like this.Skärmbild från 2013-09-06 13:32:42

Did it work ? Yeay, what could possibly have gone wrong =) The web pages goes into /var/www on your machine, so could go ahead and try changing the content in the file /var/www/index.html, just to get a feel for things. Another think I’d like to do right now is to add the ServerName to the configuration file, just to get rid of an annoying warning that pops up. So open up the apache2.conf file by typing:

> nano /etc/apache2/apache2.conf

Now add this line “ServerName localhost” at the end of the file and save it. Restart Apache2 by typing:

> service apache2 restart

The server should restart without any warnings or error messages. If you still see this kind of message “Could not reliably determine the server’s fully qualified domain name, using for ServerName” you did something wrong. Check the apache2.conf file again to make sure you got it right.

Installing PHP5

Now we are getting somewhere. We will start by installing php5 and the Apache2 support libraries.

 > apt-get install php5 libapache2-mod-php5

Directly after this we need to restart Apache2. Again type:

> service apache2 restart

Okay, now we should test that php and apache work together as expected. The easiest way is to create a small php script webpage that simply displays the php information. We do this by entering the following into the terminal:

> nano /var/www/test.php

And copy the following text into the editor:


Save the file and type the following into your browser: You should see something looking like this in your browser window.
Skärmbild från 2013-09-06 13:37:51

Leave this window open for now, we are going to use it again later on.

Now we need to install MySQL support for PHP5. This is done with one single module php5-mysql and we could install that as a single module. But we will most likely need a few other modules. Installing the modules as described here is a good way to start:

> apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json
> service apache2 restart

That line contain many of the commonly used modules among web developers.  Now go to the browser with our test.php script and click on reload. You will now find the newly installed modules in the “Module” section.

Installing phpMyAdmin

phpMyAdmin is a great tool for managing your databases. You’ll be able to create, delete, change, export and import data and much much more to your database. It’s a web based tool so you can still keep your system headless for all intents and purposes. To install type:

> apt-get install phpmyadmin

The phpmyadmin package will now be installed. You will be asked what server to support (apache2) and to replay on some password questions. The first password is the one you gave the system when installing MySQL and the second one is for phpmyadmin. You’ll also be asked to confirm the new phpmyadmin password.

When the installation is done we also need to tell apache where to find phpmyadmin. You need to include this line “Include /etc/phpmyadmin/apache.conf” into your apache2 configuration.

Now goto and it should look something like this:

Skärmbild från 2013-09-06 14:09:09

That’s all folks. Go ahead and create some really cool web based database applications.

{2} Thoughts on “Turning your RPi into a powerfull (well… maybe not so) webserver.

Leave a Reply