How to Install a Local LAMP Stack on Linux

How to install a local LAMP stack on a Linux Mint or Ubuntu computer for local PHP and MySQL development or for development on a local WordPress website.

Why Install a LAMP Stack?

When developing PHP web pages and applications on a local Linux computer it is necessary to install a local web server and PHP language interpreter. It is common to install a “LAMP stack” which includes:

  • L – Linux: already on the computer used for development
  • A – Apache: the Apache web server
  • M – MySQL: the MySQL database
  • P – PHP: to enable PHP scripts to run on the web server

With the above components installed, local WordPress websites can be set up for developing and testing WordPress themes and plugins, or simply to host and test a WordPress website locally.

In addition to the LAMP stack, phpMyAdmin is usually installed to make it easy to create and edit MySQL databases.

This article shows how to install a local LAMP stack and phpMyAdmin on a Linux Mint or Ubuntu computer. The installation was tested on Linux Mint 18, but should work on other versions of Linux Mint and Ubuntu.

Installing a LAMP Stack

Open a terminal window (shortcut Ctrl + Alt + t) and do an update before installing the LAMP server.

And then:

To install the LAMP server enter the following in the terminal window.

Important: The caret (^) at the end of the above line is not a typo and must be included in the command. (Reference and how to remove the LAMP stack.)

After entering the above command, a list of changes that will be made is displayed in the terminal window. At the bottom of the list you will be prompted whether to continue or not.

Hit Enter to continue with the installation. During the installation you will be prompted to enter passwords as explained below.

MySQL Root User Password

Enter a password for the MySQL “root” user in the dialog box as shown below. Hit Enter when done.

MySQL Root Password
MySQL Root Password

You will be prompted to re-enter the same password. Type the password again and hit Enter.

MySQL Root Password Repeat
MySQL Root Password Repeat

After confirming the password the installation will continue for a while and then complete.

Default Apache Web Server Page

The default apache web server page of the local LAMP stack should display after entering localhost in the address bar of a web browser as shown below.

Apache Default Web Page
Apache Default Web Page

This web page can be found at /var/www/html on the host machine. If the index.html file is edited or replaced, the new page will then be found at localhost in a web browser.

Installing phpMyAdmin

To install phpMyAdmin, enter the following in a terminal window.

A list of packages that will be installed is displayed followed by a prompt to continue.

Hit Enter to continue with the installation. You will be prompted to choose the web server that will be configured to run phpMyAdmin. Choose apache2 by pressing the space bar.

phpMyAdmin Web Server Prompt
phpMyAdmin Web Server Prompt

After pressing the space bar, an asterisk will appear next to apache2 as shown below. Hit the Enter key to continue.

Select apache2 by Pressing the Space Bar
Select apache2 by Pressing the Space Bar

In the next dialog box, hit Enter to select the default of Yes.

Configuring phpMyAdmin
Configuring phpMyAdmin

You will now be prompted for a password for phpMyAdmin. Type a password and then hit Enter.

phpMyAdmin Password
phpMyAdmin Password

Confirm the password by entering it again.

phpMyAdmin Password Confirm
phpMyAdmin Password Confirm

The installation will continue and then complete.

Accessing phpMyAdmin

In Linux Mint Mate phpMyAdmin can be accessed from the menu button: Menu → Programming → phpMyAdmin. Alternatively enter localhost/phpmyadmin/ in the address bar of a web browser.

Use a user name of root and the password that you selected during installation to log in to the phpMyAdmin page.

Logging in to phpMyAdmin
Logging in to phpMyAdmin

Configuring the Local LAMP Stack

Instructions for configuring the local LAMP stack to make a development environment for PHP, MySQL and WordPress can be found in the next blog post – how to configure Apache for local web development. The post includes how to set up multiple test and development web sites on a single local computer.

You may also want to configure PHP for local web development by enabling error and warning messages to display in a browser window.

One thought on “How to Install a Local LAMP Stack on Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *