Setup LAMP on Linux | How to install LAMP (Apache, PHP and MySQL in Linux) using Yum

LAMP Stands for Linux,Apache,MySQL and PHP. Most of the websites works with the above combination. The main purpose of LAMP is testing the application locally by the programmer before going to the production. Here i will show you how to install LAMP using YUM repository.




Below are the steps to install LAMP (Apache, PHP and MySQL in Linux) using Yum:-

Install Linux:

Here i am not going to show How to install Linux. The main purpose of this post is to setup AMP (Apache,MySQL and PHP) only.

Install Apache:

To start off we will install Apache.

Step 1: Open up the Terminal

Step 2: Package name of the Apache is  httpd. Install httpd using YUM. Type following Command on the Terminal and then press enter.

[[email protected] ~]# yum install httpd

Testing Apache:

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address:

http://localhost/ or

You will get the web page saying “Apache 2 Test Page Powered by CentOS”.Apache’s default document root is /var/www/html on CentOS, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory.

Install PHP:

By default Apache server supports the HTML language only, not PHP for that we need to install PHP. To install PHP please follow the steps.
Step 1: Open the Terminal again.

Step 2:  Type following line into Terminal and press enter:

[[email protected] ~]# yum install php php-mysql

Step 3. You need to restart the server after the installation of the PHP, to do that type the following on the terminal.

[[email protected] ~]# service httpd restart

Testing PHP:

For testing the PHP, Place one PHP file on to the default directory of the Apache.

Step 1. In the terminal copy/paste the following line:

[[email protected] ~]# vi /var/www/html/phpinfo.php

This will open up a file called phpinfo.php.
Step 2. Copy/Paste this line into the phpinfo file:

<?php phpinfo(); ?>

Step 3. Save and close the file. use Esc + ;wq for saving the file.

Step 4. Now open you’re web browser and type the following into the web address:

http://localhost/phpinfo.php or

The page look like below:

We have installed both Apache and PHP!. It’s working too.

Install MySQL:

Next is to install the MySQL on the Linux, follow the Steps.

Step 1: Open the Terminal and then Press Enter.

Step 2: Type the following command and then Press Enter.

[[email protected] ~]# yum install mysql-server mysql

Once  installed. Restart the httpd server for taking the effect of installation of MySQL.

[[email protected] ~]# service httpd restart

Congratulation, you just successfully installed LAMP in your machine.



Share This Post