Centos 7 | Apache, MySQL, PHP – Part 2

by / Thursday, 24 July 2014 / Published in Centos 7

Learn how to install, configure and setup Apache, MySQL and PHP on Centos 7

This is going to be an interesting exercise. I’m doing to be installing this as i write the article so hopefully this won’t become too complicated an article.

What is Apache, MySQL and PHP?

Apache is a web server application widely used as an application which servers all web content. Its an established application which needs very little tinkering once setup correctly. In today’s tutorial we will be touching on each step required to get apache up and running easily on your Digital Ocean VPS or and other Centos 7 VPS for that matter.

MySQL is the second most widely used open-source relational database management system (RDBMS). There are many large organisations which use MySQL. It’s been around since 1995 and has an excellent track record.

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Basically, it’s a scripting language which displays content of a web page and is also able to interact with many other languages / technologies and database management systems. Something HTML is not able to do.

These three technologies as well as Linux are more commonly called a LAMP stack. L for Linux, A for Apache, M for Mysql and P for PHP. As an open source project, this is commonly what you will be using to create your applications with.

So lets have a crack at it shall we 🙂

This tutorial assumes you have logged into your VPS via ssh and that you are currently the root user.

Step 1: Lets install Apache

As a baseline, I usually go to the application website, just to check which is the latest version of the application before installation. So to do that we will be going to http://httpd.apache.org/

The latest version of apache server at time of writing this article is version 2.4.10

Login to your VPS, su to the root user.

Next we will see which packages yum has for apache. The apache server package name is httpd btw.

From here we have two options.

Option 1: Install the 2.4.6-17 version via yum (Easiest option)

Option 2: Install the latest stable release. (Compile from source, more difficult)

I have decided to go for option 1 and will be covering installation of httpd from source in a coming post so watch this space.

Great! All looks good. Apache installed successfully.

Next we want to do a few checks

Ok great all is working fine. Lets not forget to add httpd to the startup script. This means even if your server shuts down for some reason the httpd service will start automatically on boot. RHEL 7 / Centos 7 has depreciated the Sysvinit Command syntax, this means your normal ‘chkconfig httpd on‘ will no longer work. We need to rather use the new Systemd Command.

Let’s see if it is now set to start on boot.

All good!!


  1. Type in your VPS’s public ip address – You should be greeted with the regular Apache welcome page
  2. Type your domain name with www – You should be greeted with the regular Apache welcome page
  3. Type in your domain name with www – You should not be greeted with the regular Apache welcome page
    1. With Digital Ocean as my host I need to add two wildcards to my CNAME records to allow Apache to serve content to my domain name with www prepended. The settings should be as follows;
      • CNAME  www  Hostname  @
      • CNAME  *  Hostname  @

Step 2: Let’s install PHP

The latest PHP package for installation via the webtatic repository is PHP v 5.4.17 I’m happy using that version so let’s install it 🙂

Testing PHP is always a good thing. To test that it’s all good I usually create a info file. To do this follow the steps below.

Step 3: Lets install MySQL (MariaDB)

So MySQL isn’t yet available on Centos 7, so as an alternative I will be installing MariaDB. MariaDB is very similar to MySQL with some differences which I will not be going into now. Feel free to read some whitepapers about the differences between MySQL and MariaDB.

I mostly develop WordPress applications and I know MariaDB is compatible with WordPress so I’m more than happy to install it.

Ok, so we all setup for root to access the database on the server. Lets login and check if all is cool.

As an addition to this installation I usually create a secondary user which I use to administer my database with, I’ll give a quick run down on how to do this also.

Step 4: Create MySQL user and allow admin rights

And we all setup :-)Hope this was of use.