How to install Apache, MySQL, PHP on Centos 7

How to install Apache, MySQL, PHP on Centos 7

To prepare your server to host dynamic websites and web apps, you have to install a group of open source software. First we install Apache web server, then install MySQL database to store the site data by using (MariaDB) and finally install PHP to process the dynamic content.


Before you begin you need a vhost or an initial server with centos 7 installed and you can do that either on your localhost or on a real online server, Now before you start you must  have a root privileges.

Step One : Installing Apache

The Apache web server is currently the most popular web server in the world, which makes it a great default choice for hosting a website

and we can install it by the following commands, open your terminal and write

 yum -y install httpd

once it installs, you can start apache on your server by

systemctl start httpd.service

and to to enable apache service to start on boot you can run

systemctl enable httpd.service

Now you can test your apache server by visiting your server’s public ip address in your web browser or write your localhost ip  if you try it on your local device


now if you can see the default centos 7 apache web page, you now running apache server

Step Two : Install MySQL (mariadb)

we need to install Mysql to organize and provide access to database where our web site can store information again in your terminal type the following commands

yum install mariadb-server mariadb

we now need to start mariadb by

systemctl start mariadb

Now we need to start the interactive script by running


this script that will remove some dangerous defaults and lock down access to our database system,now you need to make your mariadb to start on boot we use this command

systemctl enable mariadb.service

here now your database system is set up and we can move on .

Step Three :Install PHP

we will now install php component to run scripts , connect to our Mysql to get information and process the content to be viewed via your web server,also make sure restarting your httpd service

we use this command

yum -y install php php-mysql

Now you can test your php processing, we can create a simple php script called info.php and must include this file in a web root directory.

In centos 7, this directory located in /var/www/html/ . We can create this file by typing :

vim /var/www/html/info.php

you will just add to this file this php code

<?php phpinfo(); ?>

we are finished now you can save and close the file

to test that your web server can correctly display the content that generated by php script

the address you will visit will be


Now the page should contain your php version and table about php information

You can now remove the test file and add your php scripts instead.

You can watch a video of installation and if you need any help feel free to ask 🙂

Previous Post