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

Install PHP

To install PHP and PHP-MySQL components, use the command:

yum install php php-mysql

install php

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):


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: January 10 2018 18:07:05