How to Install LAMP Stack on CentOS 7
We are going to need a web server, a database, and PHP in order to serve dynamic PHP websites. LAMP is a term describing web server that includes all of these software packages.
CentOS 7 LAMP stack includes, following components.
- Apache HTTPD Server as the Web Server.
- PHP Programming Language.
- MySQL/MariaDB as the database server.
In addition LAMP stack also includes phpMyAdmin, which is a web based graphical user interface to manage MySQL Database Server.
In this tutorial we will learn how to install lamp stack on CentOS 7. We will install Apache HTTPD server, PHP 7 and MariaDB Database Server.
Do the following steps To install centos 7 Lamp Stack.
Install Apache HTTPD Server
Apache is the world's most popular open source web servers and essential part of the CentOS lamp server. Apache for CentOS 7 is provided by the httpd package.
To begin, log in as root and install the Apache httpd server:
yum -y install httpd
Next, set the httpd service to start at boot and start the service:
systemctl start httpd.service systemctl enable httpd.service
Configure CentOS 7 firewall to allow incoming http and https connections to the Apache web Server:
firewall-cmd --permanent --add-service http firewall-cmd --permanent --add-service https firewall-cmd --reload
To test apache server, open your browser and type the domain or IP address of the server. You should see the default Apache HTTP server page:
The /var/www/html folder is the document root folder of your web server. Everything that you save in /var/www/html folder can be accessed via web browser (ex: index.html).
Install PHP 7 on CentOS
Another important part of the lamp stack is PHP. PHP is a scripting language, One of the most widely used technologies for creating dynamic web content.
PHP 7 is the latest version, but not available from the default centos software repository. So will use the epel and webtatic repository which provides PHP 7 for CentOS.
First, enable the epel and webtatic repositories:
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 repolist
Next, install php7 and related packages:
yum -y install mod_php71w php71w-cli php71w-common php71w-mysqlnd php71w-mbstring
Then, restart the Apache Server:
systemctl restart httpd.service
To test PHP installation, Create the index.php file in /var/www/html with the following content:
<?php phpinfo(); ?>
After saving the file, type http://server_ip/index.php and You should see the output of PHP's phpinfo() function.
Install MariaDB Database Server
MariaDB is the default implementation of MySQL in CentOS 7. We will use MariaDB as the database server in CentOS 7 lamp stack.
Type the following command to install mariadb-server:
yum -y install mariadb-server
Next, set the mariadb to start at boot and start the service:
systemctl enable mariadb.service systemctl start mariadb.service
Run mysql_secure_installation command to set mysql root password:
The LAMP server in the CentOS 7 has been set up successfully, Combining CentOS with an Apache Web server, MariaDB database, and PHP scripting language.
What Next ?
In the next tutorial we will learn how to install phpMyAdmin on CentOS 7 with PHP 7 support.