A LAMP stack is combination of open source softwares a Linux OS, an apache web-server, a mysql database and PHP programming language. All these softwares are installed to host dynamic web applications. In this article, you will learn how to Configure LAMP Stack on CentOS 7.
You need access to a user account with sudo privileges and a package managers such as yum.
Step:1. Update Official Repository
Before you begin configuring the LAMP, You should update the package repository using below command
$ sudo yum update
Step:2. Install the Apache Web Server
As you got CentOS 7 OS running, the first step is to install the apache web server using below command.
$ sudo yum install httpd -y
Start and enable Apache by executing the following command:
$ sudo systemctl start httpd.service $ sudo systemctl enable httpd.service
Step:3. Install MySQL (MariaDB) and Create a Database
You need a database to store & organize data for your dynamic website. You can use mariadb database server that is open-source fork of the MySQL RDBMS. You can Install MariaDB with below command:
$ sudo yum install mariadb-server mariadb
Start and enable MariaDB using the following command:
$ sudo systemctl start mariadb $ sudo systemctl enable mariadb
Step:4. Run MySQL Security Script
You need to configure database, test the database, and remove anonymous users. Start by typing the command:
$ sudo mysql_secure_installation
Step:5. Install PHP & Test PHP
PHP is the part of the LAMP that processes the code for showing dynamic content. Once it is configured with the MySQL database, PHP will be retrieving information and processing it for the Apache webserver to display in your site. Install the MySQL extension along with PHP using below command.
$ sudo yum install php php-mysql
Now you need to restart the webserver to function Apache webserver with PHP,
$ sudo systemctl restart httpd.service
Step:6. Test PHP Processing on Web Server
$ sudo vi /var/www/html/info.php
If firewall is running on your server, then run the following commands to allow HTTP and HTTPS traffic:
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload
The address you need to visit on web browser will be:
After putting IP address in your web browser, you will get below page.
You should remove below file after test because it could actually give information about your server to unauthorized users using below command:
$ sudo rm /var/www/html/info.php
Hence, you have learned how to configure LAMP stack on CentOS 7. I hope I helped. Thanks!!