Configure LAMP on CentOS 7 / RHEL 7
LAMP stands for Linux, Apache,MySQL and PHP, of course Linux can be any variant (Debian/Redhat), here is the small tutorial about installing the your own web server for the testing environment in latest release CentOS 7 / RHEL 7. In this latest CentOS, MySQL replaced by MariaDB as a default database.
OS: Redhat Enterprise Linux 7 / CentOS 7
Here is the article about Step by Step installation of CentOS 7 / RHEL 7. Now you have Linux, next is to install Apache,MySQL and PHP on it. Lets install one by one.
To start off we will install Apache.
Step 1: Open up the Terminal and Switch to root user.
[raj@SRV01 ~]$ su
[root@SRV01 ~]# yum install httpd
Step 3: Start the Apache by using the following command.
[root@SRV01 ~]# systemctl start httpd.service
Step 4: To make the apache to start during the every boot, Type the following on terminal and hit Enter.
[root@SRV01 ~]# systemctl enable httpd.service
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 http://192.168.2.100
You will get the web page saying “Testing 123”, this confirms that the Apache is working fine. Apache’s default document root is /var/www/html on CentOS, the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory.
Next is to install the MySQL on the Linux, now it is a MariaDB package.
Step 1: Open the Terminal.
Step 2: Type the following command and then Press Enter.
[root@SRV01 ~]# yum install mariadb mariadb-server
Start MySQL server.
[root@SRV01 ~]# systemctl start mariadb.service
Step 3: To make the MySQL to start during the every boot, Type the following on terminal and hit Enter.
[root@SRV01 ~]# systemctl enable mariadb.service
Nex is to make the MariaDB secure by using the mysql_secure_installation command.
This program enables you to improve the security of your MariaDB installation in the following ways:
- You can set a password for
- You can remove
rootaccounts that are accessible from outside the local host.
- You can remove anonymous-user accounts.
- You can remove the
testdatabase (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with
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: Type following line into Terminal and press enter: This command includes support package for the MySQL.
[root@SRV01 ~]# yum install php php-mysql
Step 2. You need to restart the server after the installation of the PHP, to do that type the following on the terminal.
[root@SRV01 ~]# systemctl restart httpd.service
To test PHP, place a PHP file on to the default directory of the Apache. The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
Step 1. In the terminal copy/paste the following line:
[root@SRV01 ~]# vi /var/www/html/info.php
This will open up a file called info.php.
Step 2. Copy/Paste this line into the phpinfo file:
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/info.php or http://192.168.2.100/info.php
The page look like below:
Scroll down the browser to modules section to check the support for the MariaDB. you will get the screen like below.
That’s All!, you have successfully installed the LAMP on CentOS 7 / RHEL 7.