Install apache, mysql, php on ubuntu 14.04 LTSIntroduction to LAMP

Basically, LAMP is a model of web service stack. LAMP is a combination of four different open source components. Linux operating system, Apache Server, MySQL (RDBMS) and the PHP. This blog is created on WordPress and it is one of the best example of LAMP.

Install Apache, Mysql, PHP on Ubuntu 14.04 LTS

We are going to install all these components on Ubuntu so basically we have our first word L (Linux). Now let’s learn how to achieve remaining words AMP 🙂

Step 1: Install Apache

To install apache we have to install it’s meta package Apache2. Go to terminal (Ctrl + Alt + T) and type these commands:

Here apt (Advanced Package Tool) is a tool that works with core libraries to handle the installation of software on Debian or Linux system. So above command will Install apache server on ubuntu 14.04 LTS.

To identify that Apache is installed correctly or not, just open browser and type http://localhost/

You will see default Apache web page and it will look like this:

How to install apache mysql php on ubuntu 14.04 LTS

Step 2: Install MySQL

To install MySQL we have to install it’s meta package mysql-server. Type this command in terminal:

During the installation, the server will ask to select and confirm a password for a “root” user.

Now we let’s run a command to secure access of database system. Run this command to secure access:

It will ask to enter the password of the MySQL root user. Next, it will ask to change a password of the root user. Press n for it.

The sequence of next all questions will be:

  • Remove anonymous users [Y/n]? – Press Y if you want to remove
  • Disallow root login remotely? [Y/n] – Press Y if you do not want any other person to access your database within your network
  • Remove test database and access to it? [Y/n] Press Y
  • Reload privilege tables now? [Y/n] Press Y

That’s it, Database is setup successfully. Let’s install phpMyAdmin.

Step 3: Install phpMyAdmin

To install phpMyAdmin type this command:

During this installation, you will be asked to select web server to configure phpMyAdmin. When the first prompt appears, apache2 is highlighted, but not selected. If you do not hit “SPACE” to select Apache, the installer will not move the necessary files during installation. Hit “SPACE”, “TAB”, and then “ENTER” to select Apache.

The sequence of next all questions will be:

  • Configure the database for phpmyadmin with dbconfig-common? Select Yes and then hit enter
  • It will ask MySql password. Enter your MySql password and hit enter to continue
  • Last it will ask to set a password for phpMyAdmin. Enter a password and hit enter to continue and confirm password again.

Installation of phpMyAdmin is successful. Let’s go ahead and install PHP now.

Step 4: Install PHP

To install PHP we must install it’s meta package php5. Type this command in terminal:

It will install PHP 5.x on ubuntu 14.04 LTS and auto restart apache service. If it will not auto restart apache service then execute this command to restart apache service.

All set. We installed LAMP successfully on ubuntu 14.04 LTS. It’s time to create a PHP file and test it.

Step 5: Test PHP

Create phpinfo.php file in web root directory. In Ubuntu 14.04 web root directory is located at /var/www/html/.

If you are not able to create any file in html directory then execute this command to give write permission to this directory.

After executing this command you will be able to create a PHP file inside html directory. Now write below code inside created php file.

Save this file and close it. Now open a browser and type http://localhost/phpinfo.php to execute php file. Page should look like this:

How to install apache mysql php on ubuntu 14.04 LTS

If it is successful, then PHP is working correctly.

Note: As per my experience, We can not install PHP 5.x on Ubuntu 16.04 LTS because it supports the latest version of PHP (PHP 7.x). So basically if we want to install PHP 5.x then ubuntu 14.04 LTS is perfect for us.

Let me know if you need any additional help in installation. Happy to help.

You may also like:

Sharing is caring!