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.
In the next post, we’ll add WordPress so that you can run a small blog from home.