How to install Linux Apache MySQL PHP (LAMP) within Ubuntu

Installing Linux, Apache, MySQL and PHP (LAMP) within Ubuntu is incredibly easy.

Firstly you have to install the package “tasksel”. Tasksel lets you install multiple packages as one co-ordinated task.

Open a terminal window by pressing the super key and then enter “Term” into the search box. Now type the following command into the terminal window:

sudo apt-get install tasksel

When prompted to do so enter your password and press “Y” to install the tasksel package.

Now all you need to do is type the following command:

sudo tasksel install lamp-server

The required files will now be downloaded and the following screen will appear:


After a while you will be asked to enter a password for the MySQL root user. Enter the password and press the tab key to highlight the OK button. Now press return and confirm the password. Again press tab to get to the OK button and press return to continue.

To test that the installation has worked correctly open a web browser and type http://localhost.


To be able to add files to the server you need to place them in the folder /var/www.

What I generally do when running locally on my own computer is to create a symbollic link from the /var/www folder to a folder under my home directory. I find it easier to work on web projects in this way.

If you decide to do the same thing enter the following command into the terminal window:

ln -s /var/www /path/to/where/you/want/to/link/to

Obviously you shouldn’t blindly copy that code. You need to replace the /path/to bit with the path you decide to link to.

The one thing you should note is that your standard user will not have permissions to add or edit files in the /var/www folder. The best way to add and edit files is to open a terminal and run your favourite editor as sudo. (For example sudo nano /var/www/myfile.html).

On non production servers you can run the following command which makes you the owner of the /var/www folder.

sudo chown -R $USER:$USER /var/www

To test PHP create a new file in the /var/www folder (or open the symbolic link under your home directory) called testinfo.php.

Now add the following line to the file:

<?php phpinfo(); ?>

Save the file and open a web browser and type http://localhost/testinfo.php.


If all has gone to plan you should see a screen similar to the one above.

With PHP working you can now get on with testing MySQL. You can of course use the command line but it is much nicer to use graphical tools.

Within the terminal window enter the following command:

sudo apt-get install phpmyadmin


During the installation you will be asked to choose your web server. Press space to enter an asterisk into the apache2 option and then press tab to move onto the OK button. Now press return to continue.


At the end of the installation process you will be asked whether you want to add a default database as PHPMyAdmin requires a default database to continue. If you are an experienced MySQL user then you can skip this otherwise choose “Yes”.

Now you will be asked to enter your MySQL administrator password a couple of times and that is it.

Open up a web browser and type http://localhost/phpmyadmin to try it out.

phpmyadminscreen phpmyadminworking

Before I sign off I want to highlight that you shouldn’t use the permissions for Apache that have been discussed above. Follow this link to get a good insight into how permissions should be set up for Apache.

Thankyou for reading.

Leave a Reply