Raspberry Pi Project 3 – LAMPi, a Raspberry Pi based LAMP server


LAMPi – The Raspberry Pi LAMP Server Project now also has it’s own website! www.LAMPi.co.uk

Due to the horrible weather last weekend I found more time to play with my Raspberry Pi :)

I’ve got an Arduino/XBee based Wireless Sensor Network with associated storage/reporting back-end and ever since I put it together for a MSc coursework I’ve been planning to swap out the Mini-ITX LAMP server for a RasPi. In the long run I’m hoping to also add one of the XBee Series 2 modules to the RasPi so it can also take on the role of my current XBee-to-Ethernet concentrator (hence the Slice-of-pi boards in step 10). The following is a quick walkthrough of the necessary steps for setting up your own LAMPi and at the end a little section on how to read/write SD-card images, details on my first attempts to do a bit of load testing on the LAMPi with JMeter and further thoughts/links/accessory ramblings.

If you don’t want to set all this up yourself feel free to download my image. It includes everything from Step 1-7 and was created as per Step 8.1. In case you run the JMeter plan from Step 9 against one of these I’d be grateful if you could let me have results and details on your SD-card.

LAMPi a Raspberry Pi based LAMP server


Step 1 – Preparation:

Since there is still a certain amount of “will my XYZ” work with a RasPi I’m going to start by listing what my RasPi is currently connected to. If in doubt buy kit which is mentioned on the official verified peripherals list. I’ve hooked up my prospective LAMP-Pi to:

  • Samsung SyncMaster 226BW with a Belkin HDMI lead and HDMI-to-DVI adapter
  • Cherry wired optical USB mouse, Cherry GENTTIX Model No: JM-03
  • Cherry wired USB UK layout keyboard, Model No: JK-02
  • Apple AC-to-USB adapter and a no-name micro USB lead
  • CAT6 cable to a Netgear 8port gigabit desktop switch
  • Integral 2GB mini SD-card with matching adapter
  • Original Debian Squeeze image

If you are running the Squeeze image for the first time:

  • Your user name is: pi
  • Your password is: raspberry (raspberry is also the password for everything else I’ve installed below)
  • Once you are logged in start LXDE (your desktop) with: startx
  • To get screenshots install scrot and run scrot ‘%Y-%m-%d–%s_$wx$h_scrot.png’ -e ‘mv $f ~/Desktop’
  • If you’re running headless you can reboot via ssh with “sudo reboot” or shutdown with “sudo shutdown -h now”
  • If you don’t like the Midori get Chromium with “sudo apt-get install chromium-browser” and don’t forget to run “sudo chown pi:pi ~/.config” afterwards
  • Most of the below will need root privileges. Start you terminal session with sudo su or add “sudo” in front of the commands.
Step 2 – SSH:

ssh-keygen -t rsa mv /boot/boot_enable_ssh.rc /boot/boot.rc
I’m doing this from OSX so I use ssh username@yourip in a Terminal window. I think on windows you would like to use PuTTY but that’s not my world… ;)


Step 3 – Let’s install Apache 2:

groupadd www-data
usermod -a -G www-data www-data
apt-get update
apt-get install apache2

To test point a remote web browser at http://your-LAMP-Pi-ip. As usual your website’s files will live in /var/www.


Step 4 – Let’s install PHP5:

apt-get install php5
To test put a file called phpinfo.php into /var/www:
cd /var/www
nano phpinfo.php

This is what you want inside your file:

You might also want to install some of these, they all worked on my LAMP-Pi:
apt-get install libapache2-mod-php5 libapache2-mod-perl2 php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-ldap php5-mysql php5-odbc

service apache2 restart

To test point a remote web browser at at http://your-LAMP-Pi-ip/phpinfo.php


Step 5 – Let’s install MySQL:

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

To test run mysql -uroot -ppassword and replace “password” with whatever you picked when you installed MySQL (but leave the “p” in front of it!) which should get you a MySQL prompt (exit gets you out of that one).


Step 6 – Let’s install phpMyAdmin:

apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

And add the extension to your Apache php.ini with:
nano /etc/php5/apache2/php.ini

add this and save:

To test point a remote web browser at http://your-LAMP-Pi-ip/phpmyadmin


Step 7 - Let’s install TightVNCServer (Optional):

And for all those situations where your LAMP-Pi is running headless but you still want/need a full LXDE desktop I’ve installed TightVNCServer.
apt-get install xorg lxde-core tightvncserver

To start it run: tightvncserver :1
And to kill the above session run: tightvncserver -kill :1

I use Chicken Of the VNC and all I have to do is enter the LAMP-Pi IP into the host box, “1″ into the Display box, put in my password and click connect.


Step 8 – Let’s install creating and writing SD-card images under OSX:

This one isn’t for the faint hearted as it uses dd. If you don’t know what dd is or think it means “disk destroyer” better get yourself a Windows based machine and use Win32DiskImager (http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-Disk-Imager.shtml). If you’re on Ubuntu I’d recommend a nice graphical tool called ImageWriter (I’ve got Ubuntu on a Sony laptop next to me just for the task of writing images, it’s my fastest SD-card reader/writer :) . Step 8 – creating and writing SD-card images under OSX: This one isn’t for the faint hearted as it uses dd. If you don’t know what dd is or think it means “disk destroyer” better get yourself a Windows based machine and use Win32DiskImager (http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-Disk-Imager.shtml). If you’re on Ubuntu I’d recommend a nice graphical tool called ImageWriter (I’ve got Ubuntu on a Sony laptop next to me just for the task of writing images, it’s my fastest SD-card reader/writer :) . I’m doing this on OSX 10.7 but it should be very similar on all OSX versions.

8.1 To create an image from a SC-Card:

  • Insert SD-Card (my iMac has a slot at the side underneath it’s optical drive)
  • Wait until your card get’s mounted on the desktop and make a note of it’s name
  • Open Terminal and run mount. You’ll get a list of all your mounted devices and one of the lines should relate to your SD-Card. Mine was called “NO NAME” and I get this back from mount: /dev/disk3s1 on /Volumes/NO NAME (msdos, local, nodev, nosuid, noowners)
  • Take the /dev/XYZ line and strip it back to just the device without the partition. In this case that’s /dev/disk3
  • The following dd command then creates a image called lampi.img in your home directory: dd if=/dev/disk3 of=lampi.img
  • The resulting image will be the size of your SD-card but there’ll be a lot of empty space in your image so it should compress well: gzip lampi.img

8.2 To write back an image to a SC-Card:

  • Insert your target SD-card and wait until it get’s mounted to the desktop
  • Unmount the SD-card with: diskutil unmount disk3s1
  • To write the image to the SD-card with dd run: sudo dd if=lampi.img of=/dev/disk3

Step 9 – LAMP-Pi load testing with JMeter:

I’ve only done a very basic test against /phpinfo.php but, keeping in mind the size of the board and it’s power consumption, the results are impressive. It should serve very well for small/mid sized LAMP projects and with basic html content Apache2 should stand up even against higher visitor numbers. The same test runs with very much the same results in regards to speed from both an ancient 2GB Mini-SD-card and a fast 8GB SanDisk Ultra (15 MB/s, 4) but I will try again once I get my new faster SD-cards. Performance of the MySQL database will obviously be limited due to it running off the same SD-card as the whole underlying system but it will still work well as a storage backend. I’m going to write a JMeter test plan for the MySQL side later today and swap the board in as the storage/reporting back-end for my Arduino/XBee WSN to get an idea how it perfoms under real life conditions.

This is my test JMeter Test plan. All you need to do to use it is to change the IP under “HTTP Request Defaults”.


LAMPi JMeter load testing


Step 10 – Further thoughts, links and accessory rambling:

This project looks very interesting: Raspberry Pi Thin Client project And once they release a final version I’ll try to base my further images on Raspbian rather than the original Squeeze image simply because it’s based on Wheezy rather than Squeeze and has hard float instead of the soft float cheat in the original Squeeze image.

The RasPi seems picky with USB hubs, I’ve got a few cheap ones and it did not like them too much (WG111v2 fails to work as described in the RasPi forum) so I’ve got two Belkin powered port ones on order which are supposedly fixing this issue. Although not on the official “tested hardware”-list my mouse and keyboard are working ok so far but I’ve got a Apple wired keyboards lying about which is on the list, just in case.

Buffered I2C expander boards seem to be on the way, so are other proto-shield type boards and I’m trying to get some “Slice of pi” boards. They seem really nice little things, break out all the pins into a little proto area and there’s even a XBee socket. And all this for under £4 including VAT! :)

Thanks for rating this! Now tell the world how you feel - .
How does this post make you feel?
  • Excited
  • Fascinated
  • Amused
  • Bored
  • Sad
  • Angry

Add a comment »10 comments to this article

  1. Thanks for the guide. I’m currently following it and have a couple of points:

    1. Many of the commands require you to have elevated privileges. As you know this is a simple case of adding “sudo ” before the commands.

    2. In step 5 you need to restart the Apache service after installing php (otherwise your simple test will fail as it downloads the php file instead of displaying it). You restart the service using:

    sudo service apache2 restart

    3. Step 7 could be marked as optional and Step 8 seems out of place (I can’t see how setting up the SD card is part of LAMP)


    • Thanks for your comments,
      I’ve added a bit at the top on sudo su/sudo and squeezed in the apache restart after the php install.
      Step 7 is marked as optional now and I don’t think I’m going to keep it in further LAMPi builds.
      I’ve thought about step 8 for a while when I wrote the post and for installing LAMP on any other platform I would not have included it but for LAMPi it seems somewhat mandatory to mention it, it’s the only way to get the image onto the thing ;)



  2. Great piece of work. I love it….but you very kindly posted the image to load on the SD card, but you didn’t tell us what passwords you set up for MySql and phpMyAdmin. That would have helped..

    Kind Regards,


    • Hi Bartleph,
      I’ve mentioned them over on http://www.LAMPi.co.uk but must have forgotten them over here… I’ve added a bit at the top with the hint to the default password (raspberry).



  3. Hi peter, Not sure if it is an issue with me, but every time I download your 8Gb version when i use Winzip to extract the image it comes up with an error message saying the file size doesnt match what is written in the archive. I have downloaded it 5 times from FileFactory and all downloaded files fail. The 2Gb version is fine, just the 8gb version.

    Kind regards,



    • Hi Paul,

      I’m sure we can find a way to sort this out :)
      I’ve created the files on OSX 10.7 and just tried extracting them again which works fine. I’ll try WinZip on a Windows VM tomorrow at work to see if I can replicate your error message.
      I’ll also create fresh zips for you on said VM with the current version on WinZip which is hopefully going to create working files for you.
      Can I send you file links to the email address from this post?

      Kind regards,


  4. Thank you for this very useful guide. One small problem occurred in step 6:

    “To test point a remote web browser at http://your-LAMP-Pi-ip/phpmyadmin

    does not work out of the box. It results in:

    “The requested URL /phpmyadmin was not found on this server.”

    To bypass it, I was forced to manually add following line

    Include /etc/phpmyadmin/apache.conf

    in /etc/apache2/apache2.conf

    After restarting apach2 it worked. Not sure why this happened, but hopefully it helps other people with similar issues.


  5. Is there any other place to download the images linked on http://www.lampi.co.uk/ ?? I do not have nor plan on purchasing a premium account on FileFactory. Free accounts can only download files up to 500 megs.



  6. Bringing up the webserver on a Raspberry Pi | Greenhouse News

Leave a Reply to Paul Cancel reply


Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress

Hit Counter provided by www.packages-seo.com