How To Install the LAMP Stack on CentOS 7
Whether you’re new to hosting websites or a seasoned developer, you’ve more than likely heard of a LAMP stack. The LAMP stack is the base set of applications that most websites running on a Linux server are served from and is commonly referred to as “Lamp”. Rather than a single program that interacts with the website being served, LAMP is actually a number of independent programs that operate in tandem: Linux, Apache, MySQL/MariaDB, and PHP. Throughout this article, we’ll walk through installing the LAMP stack on your CentOS 7 server so you can run a website from any Dedicated Server or Virtual Private Server. Although we’re focusing on installing LAMP on a CentOS 7 server, the steps that we’ll cover are very similar across multiple Linux distributions.
Each environment differs slightly, so let’s discuss the environment that we will use throughout this tutorial. We’ll start with a clean installation of the latest version of CentOS 7 (version 7.6) on a virtual machine installed on a workstation. For ease of installation, we’ll use the root user to install the services. You can use an alternate system user if you choose, but you will need to prepend sudo to the following commands in order for them to install or interact with the software. For any environment that you choose, it is important that you are connected to the internet to access the yum repositories to download the packages to install.
Once the server is started and you are accessing the server via console or SSH terminal, we can start running through the next steps. If you need assistance with interacting with a server via terminal, please see our article on SSH.
To find out which Linux distribution you are running, use this command:
It’s now time to verify that our yum environment is clean and up to date, we’ll do this by cleaning all of the yum cache, and update yum using:
yum clean all
Now that we know what environment we’re working in let’s get started on installing the LAMP stack on CentOS 7:
L – Linux
The first part of the stack is Linux. This is your operating system and since it is already installed there no need to worry about installing it or make any modifications. Installing CentOS 7 is easy to download and install using the image files that are provided from centos.org. CentOS has a helpful installation guide if you need to reference it for additional installation instructions.
A – Apache
Apache is the next piece of the LAMP stack. Apache is the webserver software that is responsible for serving the content to your web browser from the server. It takes the requests that it receives and sends back the HTML code for your browser to interpret.
Install Apache using Yum:
yum -y install httpd
Open ports in the FW:
firewall-cmd --permanent --add-service=http -add-service=https
Start and enable apache to run when the server starts:
systemctl start httpd
systemctl enable httpd
Default Apache installation locations:
Some important server locations to remember for Apache are listed below. These are out-of-the-box defaults and can be changed as you see fit:
httpd binary: /sbin/httpd
Apache configuration file: /etc/httpd/conf/httpd.conf
Website files: /var/www/html/
Apache logs: /var/log/httpd/
M – MySQL/MariaDB
MySQL and MariaDB are what handle your website’s database. In most of today’s websites, data is not stored in flat or static files. Instead, the base of the site is coded in PHP which can pull information from your website’s database to deliver more dynamic content. MySQL and MariaDB are popular database servers that help house that information. MariaDB is becoming more widely used, so we’ll use for installation. Both are very similar in setting up and configuring.
yum -y install mariadb-server
systemctl start mariadb
Although securing mysql is optional, it is strongly recommended:
**Run through the steps on screen to secure your Mysql/MariaDB environment
Enable MariaDB to start when the server starts:
systemctl enable mariadb
Default installation locations:
Some important server locations to remember for MySQL/MariaDB are listed below. These are out-of-the-box defaults and can be changed as you see fit:
MariaDB binary: /bin/mysql
MariaDB Configuration file: /etc/my.cnf
Database location: /var/lib/mysql
MariaDB logs: /var/log/mariadb/mariadb.log
P – PHP
Most websites that exist today are built using PHP coding. PHP provides the programmer with more options for dynamic content compared to flat html code. Several PHP versions are available for use depending on what PHP version the website was built in. We’ll install the latest version of PHP.
In order to install the latest PHP version, we first need to install CentOS’s Software Collection repository (SCL):
yum -y install centos-release-scl.noarch
We’ll now have access to install PHP 7.2 :
yum -y install rh-php72
Now we’ll fix the symbolic link for the binary:
ln -s /opt/rh/rh-php72/root/usr/bin/php /usr/bin/php
Install the updated PHP Module for Mysql/MariaDB:
yum -y install rh-php72-php-mysqlnd
Restart apache to work with the newly installed PHP:
systemctl restart httpd
If your website’s code requires additional PHP and Apache modules, they can be installed using yum . If you need to verify what exactly your website is using for PHP, you can set up a PHP info page. For more information, see Setting up a PHP info page.
The LAMP stack is the minimum that is required in order for any modern website to run on a Linux server. There are many variations to these environments that can be tailored to suit your needs. Luckily, our Fully Managed Server and Core Managed servers come with the LAMP stack pre-installed and ready for you to install your website on. For more information about ordering your new server, contact our Solutions Team. Our support teams are also trained in handling issues that may arise with each component of the LAMP stack and are able to answer any questions that you might have.
About the Author: Jake Wright
Jake Wright has been immersed in computers for a majority of his career and is still fascinated in learning new technology. He's provided support in many IT related fields, including: end user support, networking, hardware, server and system administration, web hosting and training (just to name a few). He greatly enjoys outdoor activities with family and friends when he is not at the keyboard.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
How to Install Adminer MySQL Database Management Tool on AlmaLinuxRead Article
What is CGI-Bin and What Does it Do?Read Article
Top 10 Password Security StandardsRead Article
Top 10 Password Security StandardsRead Article
How to Use the WP Toolkit to Secure and Update WordPressRead Article