Latest News from 100TB

Get it from the source

Configuring A LAMP Stack On CentOS 7

Published May 19, 2017 by Hayden Smith

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. 

Why bare metal servers are the best solution for intensive apps and high-traffic websites...

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



Finally we’ll start the MariaDB service running:

    sudo systemctl start mariadb.service



Before you can use the database you need to create a root user account to manage it. This is done through a handy script:

    sudo mysql_secure_installation


This will ask you some questions, the main ones here are to set the root user password.  After that you can safely answer Y to the other questions and MariaDB will be ready to go.


If you like this you might like this infographic on Firewalls. See it here.


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 --reload


If 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.

If you are dissatisfied with your current web hosting or server provider,  contact one of our experts here and see just what we can do to improve your  experience and help grow your business.

 

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

Live Streaming: Everything You Need To Know

Previous Article

Managing Linux Users

Next Article

Receive The Latest 100TB News

Share This Post

Latest News