best web hosting

How to Install LAMP on CentOS 7?

Are you looking for a quick and easy guide to host your web application on CentOS 7 Server? then this guide is for you. I will show you how to? Install LAMP CentOS 7,  Install PHP CentOS 7, Install MariaDB CentOS 7, CentOS Install MySQL, CentOS Install Apache.

After following this guide you will be able to quickly start hosting of your dynamic PHP applications on the server.

Introduction

“LAMP” is an acronym for Linux Operating System, Apache Web Server, MySQL Database and PHP to process a dynamic application. If you want your own Dedicated Server, VPS or Cloud Server with root access then you need to make sure your server is ready to host the dynamic websites and web apps.

You have choices for OS. If you are using Ubuntu 16.04 OS then read this How to install LAMP on Ubuntu 16.04? If you are using CentOS 7 then keep on reading this tutorial, as I am going to show you the easy way to Install Lamp CentOS, Install MariaDB CentOS, Install PHP CentOS Install Apache.

Prerequisites

To start the installation of Apache, PHP and MySQL we need a Dedicated Server or VPS installed with CentOS 7 operating system with no configurations done on it.

We also need a non-root user with Sudo privileges to install lamp CentOS 7. However, you can create a non-root user but in this tutorial. I will use root user to install lamp on CentOS 7.

CentOS Install Apache

Apache initially released in 1995 is free and open source cross-platform web server software, widely used to serve the web pages on the internet. It has gain popularity since last few decades and it has been a best and default web server choice serving almost 40%-45% of active websites.

To install Apache we will use CentOS’s package manager yum, the package manager will help us pull the latest version of Apache from the CentOS repository.

1) Update your CentOS system software to latest version.

sudo yum update

As we are using sudo command, this operation is executed with root privileges. If you are logged in to the server as a non-root user then you will be asked to enter the password. In my case, I am using root user credentials so it will not ask for the password.

2) Now, install the Apache

 sudo yum install httpd 

The above command will install Apache on your server within few seconds.

3) Allow HTTP and HTTPS ports i.e 80 and 443 through firewall, and reload the firewall settings

[root@technomania ~]# sudo firewall-cmd --permanent --add-port=80/tcp
[root@technomania ~]# sudo firewall-cmd --permanent --add-port=443/tcp
[root@technomania ~]# sudo firewall-cmd --reload

4) Start the Apache web server.

sudo systemctl start httpd 

We have finished installing Apache web server and allowing HTTP and HTTPS ports through the firewall. Now type in your server’s public IP address in the browser to check the test page.

http://[server-IP-address]

centos install apache

5) Make sure you execute this command so that Apache starts automatically at boot

sudo systemctl enable httpd

6) Some useful commands

  • Check the server status
sudo systemctl status httpd
  • Stop the server
sudo systemctl stop httpd

CentOS Install MySQL (MariaDB)

Now our Web Server is installed and running up. So let us install MariaDB. MariaDB is a drop in replacement for MySQL and developed by MySQL community. MariaDB is easy to install and has some speed & performance improvements. MariaDB also has more Storage Engines. Check the detailed MariaDB versus MySQL features. Let us see how to CentOS Install MySQL?

1) Install MariaDB Centos.

We will use again the CentOS package manager yum, to pull the package from CentOS repository.

sudo yum install mariadb-server mariadb

2) Start the MariaDB with the following command.

sudo systemctl start mariadb 

Secure MySQL/ MariaDB Installation

As our server is running up, let us secure the database by running the command. This will extra security level to the database by restricting access to the database.

 sudo mysql_secure_installation

As we have just installed MariaDB, we don’t have root password setup so keep it blank and hit enter. It will ask you whether you want to setup the root password, then type Y and hit enter.

Set root password and for rest of the questions just hit enter and finish the process.

3) Make sure MySQL/MariaDB server starts at the boot

 sudo systemctl enable mariadb

4) Check the status of MySQL/MariaDB 

sudo systemctl status mariadb

5) Stop the MySQL/MariaDB server (optional don’t execute it now)

sudo systemctl stop mariadb

We have successfully installed the MySQL/ MariaDB server.

Install phpMyAdmin to manage all your databases through a web interface. Check out this guide How to install phpMyAdmin on CentOS 7?

Install PHP Centos 7

PHP is the server-side programming language and used to process the dynamic content of the website, it is capable of communicating with the MySQL database, retrieve & process the data and hand over to the web server to display it.

To install PHP we will use CentOS’s package manager yum. We will also include php-mysql package along with PHP.

sudo yum install php php-mysql

Reboot the Apache web server in order to make PHP work with Apache.

sudo systemctl restart httpd

Check the PHP version installed


[root@technomania ~]# sudo php -v<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
PHP 5.4.16 (cli) (built: Nov 15 2017 16:33:54)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[root@technomania ~]#

We have successfully installed PHP on Centos 7.

Test the Web Server for PHP Processing

As we have finished installing Apache, MySQL, and PHP we will now test whether our server is able to process PHP files or not. To test the web server for PHP processing we will simply create a phpinfo.php file. Basically, it is the PHP configuration and settings page which is used to ensure that your settings are applied correctly to the server or not.

Our root directory in CentOS 7 is at var/www/html we will create our phpinfo.php file in root directory. We can create a file using command or we can simply connect our server using WinSCP file manager tool and create a file, I will be using the command to create a file in the root directory.

[root@technomania ~]# sudo vi /var/www/html/phpinfo.php
This command will create a blank page named phpinfo.php in the root directory, we need to put the below PHP code in it.
<?php phpinfo(); ?>

Now the PHP file is created it’s time to access this file through the browser. To access this file you need to use the below-given URL, just replace [server-IP-address] with your server IP address.

http://[server-IP-address]/phpinfo.php

After accessing this URL you will probably see this information on the screen.

Install PHP Centos 7

 

Conclusion

Now that you have installed the LAMP stack on CentOS 7, your server is ready to host the dynamics websites and web apps. You have further options to install different CMS like WordPress, Joomla, or Laravel. In short, using this article you just created a platform to host the different types of websites on your server. Next, you can secure your server by installing SSL certificate on it.

Kindly let me know if you face any issues while following my step by step guide on How to install LAMP on CentOS 7? You can comment your problems below and I will try to resolve your query as soon as possible. If you like this article don’t forget to share this with your friends & colleagues. If you find my articles are helpful then do subscribe to our newsletters.

Thank you for reading.

best web hosting

One Response

  1. www.mackoaching.net June 8, 2018

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.