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.
sudo apt-get update
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.
You will be prompted to re-enter the same password. Type the password again and hit Enter.
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.
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.
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.
After pressing the space bar, an asterisk will appear next to apache2 as shown below. Hit the Enter key to continue.
In the next dialog box, hit Enter to select the default of Yes.
You will now be prompted for a password for phpMyAdmin. Type a password and then hit Enter.
Confirm the password by entering it again.
The installation will continue and then complete.
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.
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.