Chat / Contact

Latest News from 100TB

Configuring A LAMP Stack On CentOS 7

Today we’re exploring LAMP. Nope, not the thing in the corner of your room providing decorative illumination, but the software stack comprising of Linux, Apache, MySQL (or increasingly MariaDB) and PHP (or Perl, or Python, etc). It’s tried and tested and used on a large quantity of web servers on the internet.

This time the aim is to show you how easy it is to take a basic CentOS 7 and get it up and running to serve a PHP based website using the combination of Apache, MariaDB and PHP. For this guide, we are going to assume you have a dedicated server, or VPS, running a bare CentOS 7 installation and are using a user account with sudo or root access.

Installing Nano

For the first, optional, step we can install the nano text editor. If you are familiar with and would rather use vi, then feel free to swap the nano sections of the guide for vi. If you don’t know what I’m talking about then you probably want to install nano for use. sudo yum install nano

What is MariaDB?

With that step taken care of, the next thing to do is to install MariaDB. For those who are unfamiliar, MariaDB is a fork of MySQL made by the original MySQL developers after the acquisition of Sun Microsystems (then owner of MySQL) by Oracle. The aim of MariaDB is to remain compatible with MySQL in order to be a drop in replacement. With concerns that Oracle would be moving MySQL to a closed source project, many Linux distributions have moved to offering MariaDB instead of MySQL in their standard package, CentOS is one of those distributions.

Installation is as simple as: sudo yum install mariadb-server mariadb

Once installed, next we need to ensure it’s enabled to start up after the server reboots: sudo systemctl enable mariadb.service

Installing Apache

Once your database is configured the next step is to install the Apache web server, which is done with the following command: sudo yum install httpd

Once installed, it also needs to be enabled and started: sudo systemctl enable httpd.service sudo systemctl start httpd.service

Now if you browse to your server’s IP address in a web browser you should see a CentOS test page for Apache. If not then the server’s firewall may be blocking you. The default CentOS firewall is now firewalld and you can allow traffic to your web browser through it with the following commands: sudo firewall-cmd --permanent --zone-public --add-service=http sudo firewall-cmd --permanent --zone-public --add-service=https sudo firewall-cmd --reloadIf you try again now you should be able to see your the test web page.

Installing PHP

The next step is to install PHP, which is again a simple task from the repositories: sudo yum install php php-mysql

This will install PHP and the required module for PHP to be able to interface with MySQL/MariaDB. Once installed, we’ll need to restart Apache so that it can make use of PHP: sudo systemctl restart httpd.service

Now to test that PHP and Apache are working well together we’ll create a test file. sudo nano /var/www/html/info.php

Paste in the following text:

<?php phpinfo(); ?>Save and exit the file, then go back to your browser window where you previously brought up the test page, and append “/info.php” to the end of the server’s IP address. You should then get a PHP branded page with information about the installed version of PHP.If that last step worked as expected then you are ready to go and start setting up your chosen website software on your server.

To follow Hayden’s next technical topic, sign up for our weekly newsletter below.