Raspberry Pi Home Server: Part 12, The LAMP Stack

Note: This article is part of a series. See the Index for more information.

Self-promotion: I’ve recorded this series as a screencast for Pluralsight:
If you have a Pluralsight subscription, please consider watching it. Thanks!

Updates: I haven’t had any reports of trouble with this post since the Jessie release of Raspbian came out, so I’m assuming it all still works until I hear otherwise.

LAMP stands for “Linux, Apache, MySQL, and PHP”, and it’s the technology stack a lot of web projects in the Linux world are built on.

  • Linux is the OS, of course, the bottom layer of the stack.
  • Apache is a web server that runs on Linux.
  • MySQL is a database that applications can use to store their stuff.
  • PHP is a web programming technology used to write web applications.

If you’re not planning to run any web applications from your server, you can obviously skip this post. If you want to run WordPress, though, you’re going to need the LAMP stack. Through the magic of the Advanced Packaging Tool (APT), you could just install WordPress, and the dependencies would come along for the ride, but where’s the fun in that? I’d rather make sure I have a solid LAMP stack before installing any applications on top of it.


This was taken care of in previous posts. Log in to the Raspberry Pi as the “pi” user, and get to a command prompt. If you can do this, you’ve handled the “L” part.


To install the next layer of the stack, the Apache web server, version 2, type the following command, answering “Y” when prompted to confirm.

sudo apt-get install apache2

If everything went well, you should now have a working web server. You can test this by opening a browser from another computer on your network, and navigating to the address of the Raspberry Pi. You should see a generic “It Works!” message.



Next up is the MySQL database engine, which applications will use to store their information. Type the following to install MySQL:

sudo apt-get install mysql-server-5.5

You’ll be prompted multiple times during the install to provide a password for the root user. It should look like this:


This is not the same “root” as Linux itself. This is a MySQL database account that will own the server. Whatever password you/u assign, make sure you write it down somewhere, or put it in a password safe program. You will eventually need it.

When the installation has completed, check to see that MySQL is working by typing the following:

sudo mysql –uroot -p

This says to start the MySQL command-line interface, as the Linux user “root” and log in as the MySQL user “root”, prompting for the root password.

To get a list of databases on the new MySQL server, type “show databases;” (don’t forget the semicolon). You should see a list similar to this:


Note: If you do somehow forget the semicolon (even though I specifically mentioned it), you can always type a single semicolon on a line by itself and press enter to complete the command.

Type “exit” to get out of the MySQL command line and back to the regular Linux command line. Now that MySQL is installed, there is some security configuration that needs to be done. Fortunately, a script exists that will take care of it for you. Type the following to run the script that will lock down the MySQL installation, providing the password you chose above when prompted.


If you didn’t assign the root user a password, then just hit enter when prompted for it, and “n” when prompted to set one.


So far you have the L, A, and M layers installed. Last up, you need PHP. Actually, you need a few different PHP components. Install them all in one shot by passing all of their names to apt-get at once like this:

sudo apt-get install php5 php5-mysql php5-gd

This installation will take a little while. I don’t have a simple test for you to verify the PHP installation, but you’ll know if it works soon enough.

What’s next?

In the next post, we’ll add WordPress so that you can run a small blog from home.

This entry was posted in Computers and Internet, Home Server, Raspberry Pi and tagged . Bookmark the permalink.

15 Responses to Raspberry Pi Home Server: Part 12, The LAMP Stack

  1. Pingback: Raspberry Pi Home Server: Index | MelGrubb.ToBlog()

  2. Pingback: Raspberry Pi Home Server: Part 11, OpenVPN | MelGrubb.ToBlog()

  3. Brian says:

    Dear Mel,
    I’m getting this error:
    pi@RPHS ~ $ sudo mysql –uroot -p
    Enter password:
    ERROR 1049 (42000): Unknown database ‘–uroot’
    Can you help?

  4. gilad says:

    Asked only for password (seems it assumed root already)
    Oddly, today when working ont he WordPress installation the command did work as written with the -uroot.

  5. Pingback: Raspberry Pi Home Server v2: Introduction | MelGrubb.ToBlog()

  6. Clay says:

    I ended up not doing this section on LAMP. Under Stretch, it seems like some of the components have been deprecated. If you end up doing another update on this series for Stretch, let me know if you want a beta tester. I’d be happy to help out.

  7. Mel Grubb says:

    I’m currently working my way through the whole thing again as I update my PluralSight course for stretch. It’ll get there.

  8. Jason Edgar says:

    I was getting the following in the MySQL install
    Package ‘mysql-server-5.5’ has no installation candidate
    so I installed with
    sudo apt-get install mysql-server
    That seems to miss the password entry part

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s