Introduction

In this post I will show you how to install LAMP in CentOS 7. You may think that it is as simple as running several yum install commands, but it is not. Mostly because CentOS is delivered with an outdated PHP version. It is version 5.4, which already reached End Of Life.

Therefore, if you want to stay secure and up to date, you will have to use a third party repository to have the latest version of PHP installed. Other than that, you will install Apache and MariaDB as usual, using simple yum install commands.

Remi’s RPM Repository is the one you need in order to install the latest version of PHP in CentOS or RHEL. By accessing the link, you will have available a very nice Configuration Wizard in which you can select the Operating system, the PHP version that you want and the Type of Installation that you require. After selecting that, you will have the Wizard answer available. Below is an example of a wizard answer for the latest version of PHP to be installed on CentOS 7.

Now, let’s follow the instructions from the Remi’s website in more detail. If you didn’t already install the EPEL repository, you can do it with the command:

Then install the Remi repository with the command:

You will then install yum-utils package to have the yum-config-manager available:

Enable the Remi repository:

Update all the repositories:

To install PHP run the command:

If you want to install additional packages, just search for them using the command:

Then, if you find a package that you would like to install, just use the yum install package-name command. One recommended package would be php-mysql. To install it, use the command:

To check the php version installed, run the command:

Now that you have the latest version of PHP installed, you can proceed and install the rest of the stack.

Install Apache

Installing apache is very straight forward. Just execute the following commands to install, start and enable the Apache service:

Installing MariaDB, the open-source fork of MySql, you should run the following commands:

To setup MariaDB run the secure installation script with the following command:

All you have to do now is to restart the Apache service with the command:

Test the PHP installation

You can test the PHP installation in your browser by creating a info.php file inside /var/www/html/ (default DocumentRoot). Then you add the following line inside the file:

Configure the Firewall for Apache

If you have the firewall installed, as I showed you in a previous post, you should configure it for the Apache webserver. To do this, execute the following commands:

Now you could do a system reboot and start creating your Virtual Hosts for your websites. You can then install Wordpress, Drupal or Jekyll to create your web content.

The options are endless.

Enjoy!