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.

Update: See updated local LAMP stack installation instructions for Linux Mint 19 and 19.1 which have been updated for these newer versions. For Linux Mint 18.x, continue reading below.

Installing a LAMP Stack

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

sudo apt-get update

And then:

sudo apt-get upgrade

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

sudo apt-get install lamp-server^

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.

0 upgraded, 30 newly installed, 0 to remove and 21 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 183 MB of additional disk space will be used.
Do you want to continue? [Y/n]

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.

sudo apt-get install phpmyadmin

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

Need to get 5,835 kB of archives.
After this operation, 32.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]

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.

4 thoughts on “How to Install a Local LAMP Stack on Linux”

  1. I suspect that while this page is great information I cannot get MySQL to ask for a password by default. Instead I have to run “sudo mysql_secure_installtion” to set a password.

    I also find that PHPMyAdmin does not accept Root or Admin as a user and does not by default create a new user.

    1. You can setup a password for root with out using ‘mysql_secure_installtion’ by login onto mysql
      # mysql -u root -p mysql
      when it prompts for a password if no password is set just press enter.
      When logged on at the mysql prompt you then enter the following details:

      USE mysql;
      CREATE USER ‘root’@’localhost’ IDENTIFIED BY ”;
      GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’;
      UPDATE mysql.user SET authentication_string = PASSWORD(”), plugin = ‘mysql_native_password’ WHERE User = ‘root’ AND Host = ‘localhost’;
      FLUSH PRIVILEGES; Here you press enter.

      After you exit mysql the type the following data into the command line.

      # mysql -u root -p press enter
      you will be prompted for the password for root.

Leave a Reply

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