INSTALLATION AND CONFIGURATION OF LAMP ON CENTOS 7
LAMP stands for Linux, Apache, Mysql, and PHP.
In this tutorial, We are installing our own web server in the testing environment on Centos 7.
Now, you have Linux next is to install Apache, PHP, Mysql on it.
First, switch to root user to install Apache packages.The package name of apache is httpd.
#yum install httpd -y
Once installed, Start and enable the service using the below command:
#systemctl start httpd.service
#systemctl enable httpd.service
To check whether apache has installed correctly and we can test apache to ensure its working properly.
Open the Browser and type the below command in URL:
We will get the following test page which confirms that apache is working fine.
Apache’s default document root is /var/www/html and Configuration files are stored in /etc/httpd/conf/httpd.conf
Also,Some addirional configuration files are stored under /etc/httpd/conf.d/directory.
Install MySQL Database
Next, We need to install Mysql database.
DOWNLOAD THE REPOSITORY:
Install the repository:
#rpm -Uvh mysql-community-release-el6-5.noarch.rpm
Install the Mysql packages using the below command:
#yum install mysql-server -y
#chmod 1777 /tmp
Mysql database runs on /uses port number 3306 to communicate with databases/servers.
Make sure you have installed firewalld and service is running and run the below command.
#firewall-cmd –permanent –zone=public –add-port=3306/tcp
#firewall-cmd –permanent –zone=public –add-port=80/tcp
Make sure to start the service of Mysql before going to next step:
#systemctl start mysqld
#systemctl enable mysqld
Next, We need to run a script mysql_secure_installation which helps in improving security and to remove some defaults which are dangerous to the Production environment.
It will prompt to setup the root password for the MySQL Database followed by asking, Do you want to change the root password, Type “yes” and enter and New Password and confirm.
Also, You will be asked series of questions, You should answer Y(yes) to all of the remaining questions as shown below:
You can login to Mysql database using the below command:
#mysql -uroot -p”password”
By default, Apache server supports only HTML languages, For that We need to install PHP.To install PHP use the following steps:
#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#yum install php70w php70w-opcache php70w-mysql php70w-mbstring [This command also install support packages of Mysql]
Now, We need to restart the httpd service after the installation of PHP.
#systemctl restart httpd.service
In order to test the working of PHP, We need to create a PHP file in the default root directory of APACHE server.
We will create a file called info.php under /var/www/html directory and we can verify more details about Installed PHP on the browser.
This will open a file called info.php
Copy and paste the below code into the file:
Save and close the file.
Now open the browser and type the following command:
You will see the following Page like this:
You can scroll down and check many details on this Page.
That’s All, We have successfully installed LAMP server on Centos 7.