How to create a LAMP server on CentOS 7

Comprised of Linux, Apache, MySQL, and PHP, the LAMP stack is a versatile platform on which you can build your website.

The LAMP stack is one of the most popular web server configurations in use today. Comprised of Linux, Apache, MySQL, and PHP, the LAMP stack is a versatile platform on which you can build your website.

For this tutorial, we will be using CentOS, a free version of Red Hat Enterprise Linux, to provide the Linux aspect of the stack. We will be installing and configuring Apache, MySQL, and PHP on CentOS 7.

Creating LAMP server on CentOS 7


You will need:

  • A computer or VM with CentOS installed
  • A working network connection

Configure CentOS

1. Install firewalld

It is recommended that you install a firewall on your server for added protection. In this case, we will be using firewalld, a simple firewall daemon.

To begin, we will install the firewalld package:

# yum install firewalld

Next, we will enable firewalld, so that it starts on boot:

# systemctl enable firewalld

And restart the system to finalize changes:

# reboot

2. Set the Servers Hostname

NOTE: This step is optional depending on how your server is set up and your use case

To set the server’s hostname, run:

# hostnamectl set-hostname HOSTNAME

Where HOSTNAME is the hostname, you want to use.

Install Apache, MySQL, and PHP

3. Install Apache

Now, we will install the Apache HTTP server. To do this, run:

# yum install httpd

Installing httpd

It will install the httpd package. Now, add the HTTP service to firewalld with:

# firewall-cmd --add-service=http

Now, reload firewalld:

# firewall-cmd --reload

Next, restart the httpd service:

# systemctl restart httpd.service

Then, enable the service, so it starts on boot:

# systemctl enable httpd.service

4. Install MySQL

Once Apache is installed, we can install the MySQL database software. CentOS replaced MySQL with MariaDB in its repositories; however it is still possible to install MySQL.

To do this, first add the MySQL 8.0 repositories:

# yum localinstall

Adding the MySQL repo

Once the repository is added, install MySQL:

# yum install mysql-community-server

Installing MySQL

Once the MySQL package is installed, we must enable it:

# systemctl enable mysqld

And start it:

# systemctl start mysqld

5. Install PHP

Now we will install the PHP programming language onto the system. First, enable the EPEL repository:

# yum install epel-release

Enabling the epel repo

After you have done this, enable the remi-php73 repository:

# yum install

Adding the remi repo

Next, enable the repository:

# yum-config-manager --enable remi-php73

Enabling the remi repo

Finally, install PHP:

# yum install php

Installing PHP


Now you have a fully functioning LAMP server on which you can build whatever you want.

Brandon Hammond
Hello, my name is Brandon Hammond, I am an avid Linux enthusiast, programmer, and contributor here at FOSS Linux. Linux is one of my passions, and when I'm not attending college I'm usually tinkering with it in a VM.


Please enter your comment!
Please enter your name here




How to create a Fedora Games Live USB drive in Linux

One of the best Fedora spins that has been for a while and also being well maintained is the Fedora Games. The Fedora Games spin is a great showcase of the best games available in the Fedora operating system.


cool and fun linux commands
The real purpose of this article is to help Linux newbies get comfortable and confident with the Linux command-line.  While knowledge and comfort of the Linux GUI allow great power, it is the mastery of the command line, or CLI, affords the Linux user unlimited power and certifies them as a Linux power user well on their way to becoming an expert.
essential linux commands
Last week, we shared with you several "cool and fun" commands to get comfortable and confident with the Linux command-line. In our quest to further aid Linux users with mastery of the command line, or CLI, we present you with a variety of command-line utilities essential for all Linux users, regardless of proficiency level.
best linux distros beginners
Making the shift to Linux is not as complicated as some people make it out to be. There is a variety of Linux distributions available that cater to the needs of people who are planning on making the jump to Linux from any other operating system.