Monday 31 March 2014

Raspberry Pi LAMP Server

This is a simple guide to setting up a Raspberry Pi computer as a 'LAMP' (Linux, Apache MySQL, PHP) server.

I'll be using it at a later date to create a simple PHP-based To-Do list type system, which I'll cover in later posts.

Download and install the latest version of Raspbian from the Raspberry Pi website.
As I'm using linux, the command I needed was:

sudo dd bs=4M if=2014-01-07-wheezy-raspbian.img of=/dev/sdh

Boot up the Pi and go through initial setup:
  • Expand filesystem
  • Change user password
  • Boot to console
  • Enable SSH Server
  • Force audio through 3.5mm
  • Update tool to latest version
Finish the setup tool and from the command line run updates:

  • sudo apt-get update
  • sudo apt-get upgrade
Install the LAMP stack:

  • sudo apt-get install apache2 php5 mysql-client mysql-server
During this installation process you'll be asked to provide a root password for the MySQL server.
(Optional) Install PHPMyAdmin


  • sudo apt-get install phpmyadmin

This should boot the PHPMyAdmin installer tool:
  • In the first screen select the web server to configure (apache2).
  • Select yes to configure database for phpmyadmin with dbconfig-common.
  • Enter the root MySQL password. Create a phpmyadmin password for the sql server.
Now would be a good time to save the progress made. Shutdown the Pi with
  • sudo shutdown -h now
Once the systems shutdown, remove the memory card and make a backup of the cards data. I use the dd command again to create a gzipped image


  • dd if=/dev/sdh | gzip > /path/to/backups/backupname.img.gz

This allows backups to be restored just as easily, using the command

  • gunzip -c /path/to/backups/backupname.img.gz | dd of=/dev/sdh
If you want to run the Pi 'headless' - without screen or keyboard, now would be a good time to disconnect them.

Once the backup is done, put the SD card back in the Pi, and reboot.
Give it a little while to reboot, and then from your P, connect to it via SSH. On linux this is a command like

  • ssh HostnameOrIP -l pi
Once logged in, you can control the Pi from the command line as you were able to previously.


No comments:

Post a Comment