Kim Spasaro

Installing a LAMP Stack

July 16, 2016 , , ,

Ubuntu has a really great guide to setting up a LAMP stack. Still, it’s a little dense. Here’s an overview to setting up a LAMP stack.

What’s a LAMP Stack?

LAMP is an acronym for Linux Apache MySql PHP. LAMP is a backend web stack for developing websites that:

The same stack used on Windows and Mac are called WAMP and MAMP respectively.

How to Install a LAMP Stack

Here I’ll provide the steps to installing a LAMP stack for local development. This tutorial assumes you are running Ubuntu or some other Linux distro that uses the Synaptic package manager.

Install the LAMP Server

In your terminal, type:

$ sudo apt-get update
$ sudo apt-get install lamp-server^

Note: Don’t type the $ sign. That indicates the beginning of your input to the terminal (notice that your terminal probably starts up with username@computer-name: $).

Install Apache

$ sudo apt-get install apache2
$ sudo service apache2 restart

After restarting, you can check that Apache is running by going to the url http://localhost. If the Apache server is running you will get some sort of welcome page. Congrats! You have a local server!

Install MySQL and PHP

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Login to the MySQL console:

$ mysql -u root -p

The above will log you into the mysql console, which uses MySQL commands instead of Bash commands. Notice that instead of prompting input with the $ you see in the Bash console, MySQL prompts you for commands with mysql>.

Now set your password:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

You can now login to MySQL anytime with $ mysql -u root -p which will then prompt you for your password.

Configuring Your LAMP Stack

Configure Apache Sites

In order to actually develop using your LAMP stack you’ll need to configure Apache to point localhost (the url for accessing your local dev sites) to your local development environment. By default, Apache points localhost to /var/www. This is no good for local development because you need root privileges to edit the contents of /var, which would require you to use sudo for all of your local development–and this is bad. A better location would be something like /home/{username}/dev/lamp. From now on, this tutorial assumes /home/{username}/dev/lamp will be the location of sites you develop locally using LAMP.

Configure Virtual Hosts

Navigate to Apache’s sites-available directory:

$ cd /etc/apache2/sites-available

In this folder you should see two files, default-000.conf and default-ssl.conf. Copy the first file to a new file called localhost.conf and open that file:

$ sudo cp default-000.conf localhost.conf
$ sudo gedit localhost.conf &

Change the contents of this file to the following, where {username} is your username (no braces):


	ServerAdmin webmaster@localhost
	DocumentRoot /home/{username}/dev/lamp/
	ServerName localhost
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined


Enable New Virtual Host Configuration

$ sudo a2ensite localhost

Disable Default Virtual Host Configuration

$ sudo a2dissite 000-default

Restart Apache

$ sudo service apache2 restart

View Your Sites

You should now be able to navigate to localhost in your url bar and see an Apache confirmation page. You can make sites in your dev/lamp folder and navigate to them using localhost/folder-name. For example, to make a test WordPress site you can download WordPress to dev/lamp/wordpress and then run the WordPress installation at localhost/wordpress.


Having problems? Things to check: is Apache running? Did you restart it last time you made changes? Do your file permissions allow viewing?

If you want to use SSL you’ll need to copy/modify the default-ssl.conf file in /etc/apache2/sites-available, enable the new ssl conf file, disable the default conf file, and restart Apache.

If you get an error about your password policy not permitting a password, you probably have to fiddle with the permissions you set during your initial setup. See here: