How To Install LAMP Stack on Ubuntu

This tutorial will explain how to install LAMP Stack on Ubuntu. LAMP is not a software or technology but it is a group of technologies that make possible to create an environment for creating great websites (using PHP mainly).

LAMP is the union of Linux + Apache + MySQL or MariaDB(In this tutorial we will install MySQL) + PHP.

How to Install Apache

First thing we need to do is to install Apache. Open the Terminal and run the following code:

sudo apt-get install apache2

The terminal will ask you for your password, type it and press enter.

To be sure that you have installed Apache correctly type in the URL bar:

http://localhost/

Apache Ubuntu

How to Install PHP

To install PHP, open the terminal and run the command:

sudo apt-get install php5 libapache2-mod-php5

Then restart Apache in order to work with PHP.

sudo /etc/init.d/apache2 restart

How to Install MySQL

To install MySQL in Ubuntu open the Terminal and type:

sudo apt-get install mysql-server

If you want other computers on your network to view the server you have created, you must edit the “Bind Address”. Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line bind-address = 127.0.0.1 and instead of 127.0.0.1 enter your IP address.

In the Terminal enter the following line:

mysql -u root

Now enter your desired root password. Change my_password with any password you like:

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

I strongly advice to install phpMyAdmin because it’s the easiest tool to edit your databases. To install phpMyAdmin, open Terminal and run the command:

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

Now let’s get PHP work with MySQL.

gksudo gedit /etc/php5/apache2/php.ini

Find this line ;extension=mysql.so and remove ;.

Then, you need to restart Apache:

sudo /etc/init.d/apache2 restart

After you restart Apache, your environment is ready for developement 🙂