Installing Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu

What is LAMP?

LAMP group of open source software that you might use to run your linux based web servers. LAMP means Linux, Apache, MySQL and PHP. As your virtual server is already running Linux, We need to install rest of other software stack.

Getting Started

In order to follow the steps presented in this tutorial, you need root privileges on Linux. All the steps performed here are for Ubuntu 14.04 for Server. This might be little different in other Linux distribution. However in previous Ubuntu version, steps might be similar. Before going to install LAMP stack, first update the download mirrors by running this command

sudo apt-get update

Step One — Apache Installation

Apache is the most popular open source web server that is running on 50% of all the web servers around the world. To install Apache on Ubuntu run below commands in SSH client or Terminal.

sudo apt-get install apache2

This will install Apache web server. To test installation is successful directly browse your VPS IP (e.g. http://12.34.56.789) or http://localhost (if installing on desktop) in web browser. This will shows words like “It works!”

If you don’t know your IP address you can find IP using below command

ifconfig eth0 | grep inet | awk ‘{ print $2 }’

Step Two — MySQL Installation

MySQL database management system is also an Open Source database management system and this used to organise and retrieve data stored in database.

MySQL can be installed on Ubuntu using below command:

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

During MySQL installation, setup might prompt you to set password for database root user. Specify root password if you want to set password. If you haven’t specified password here, don’t worry you can set it later using MySQL shell.

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.

After successful installation of MySQL, next step is to activate it using below command.

sudo mysql_install_db

Next finish MySQL installation by running below command

sudo /usr/bin/mysql_secure_installation

This will prompt you to enter current root password and also allows you to change root password. Next you will be prompted you for many other options. It’s better you say “yes” for each option.

The prompt will ask you for your current root password.

Remove anonymous users? [Y/n] y 
… Success!
Disallow root login remotely? [Y/n] y
… Success!
Remove test database and access to it? [Y/n] y
— Dropping test database…
… Success!
— Removing privileges on test database…
… Success!
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…

At the end of this script, MySQL will reload and implement the new changes.

Step Three — PHP Installation

PHP (Hypertext Pre-Processor) scripting language used to build dynamic webpages. PHP is also an open source. PHP can be installed using below command.

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Latest PHP setup automatically adds index.php in index directory. If it is not added by default, you can also add it yourself by editing /etc/apache2/mods-enabled/dir.conf.

sudo nano /etc/apache2/mods-enabled/dir.conf

Add index.php after DirectoryIndex like this:

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Congratulations! LAMP stack is successfully installed.

Show your support

Clapping shows how much you appreciated Adnan Umer’s story.