Installing Apache/MySQL/PHP on CentOS 7

LAMP or Linux, Apache, MySQL, and PHP is the default software stack most PHP+MySQL based applications use, it's the easiest and quickest way to get your PHP+MySQL application online. A LAMP stack can be installed on your CentOS install using the following commands.

Install Apache

To install and start Apache, input the following commands:

 yum -y install httpd

install apache

Once Apache is installed, you can start it by using the command:

 systemctl start httpd.service

start apache

To enable Apache to start on boot, use the following command:

 systemctl enable httpd.service

enable apache

Configure firewalld to Allow Web Traffic

CentOS 7’s built-in firewall is set to block web traffic by default. Run the following commands to allow web traffic:

 sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --add-service=https --permanent

 sudo systemctl restart firewalld

Install PHP

To install PHP and PHP-MySQL components [default version PHP 5.4], use the command:

yum install php php-mysql

install php

To install latest version,

Click on PHP 5.6 OR PHP 7.x

Restart Apache web server to put all changes into effect:

systemctl restart httpd.service

restart apache

Install MySQL

To install MySQL (in this case MariaDB), input the following commands:

yum install mariadb-server mariadb

install MariaDB

Once it's completed, use the following command to start the MySQL:

systemctl start mariadb

start mariadb

use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users):

 mysql_secure_installation

Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instructions:

secure install

To enable MariaDB to start on boot, use the following command:

systemctl enable mariadb.service

enable mariadb


Last Modified: July 26 2018 15:23:06