fbpx

How to setup LAMP Stack on CentOS 7/RHEL 7

How to setup LAMP Stack on CentOS 7/RHEL 7

Default Article Image Vulr Banner

Choosing CentOS 7/RHEL 7 and LAMP for your webserver is a solid choice! CentOS 7/RHEL 7 have been around for years and are supported until 2023, which means years of support and proven stability!

Not Using CentOS 7 or RHEL 7? Check out our other articles on other operating systems!

Debian 10Ubuntu 18.04
CentOS 8

Step 1: Update All Software Packages

Before setting up LAMP it’s generally a good idea to update all of the repositories and software packages.

sudo -s

sudo yum update -y

Step 2: Install and setup Apache (HTTPD)

yum install httpd httpd httpd-tools php-mysqlnd php-fpm mariadb-server -y

Optional packages to install to make future management easier

yum install nano wget git net-tools yum-utils -y

Next we need to enable the HTTPD service we just installed

systemctl start httpd
systemctl enable httpd

Next check the status of the HTTPD service

systemctl status httpd

Output (press Q once you verify your service is running)

Next we will need to allow HTTP and HTTPS through the firewall

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Now we need to configure permissions

chown -R apache:apache /var/www/html/*
chcon -t httpd_sys_rw_content_t /var/www/html/ -R

Step 3: Setup MySQL (MariaDB)

systemctl start mariadb
systemctl enable mariadb

Check to make sure the service is running

systemctl status mariadb

Next we need to configure MySQL by setting up a root password and securing it.

mysql_secure_installation

Since this is a fresh configuration there will be no MySQL root password so simply press enter and set one. Once a password is set you can simply press enter through the rest of the configuration


Step 4: Test Installation

Navigate to the IP/Domain of your server and ensure it is online. Additionally, you can follow the steps below to test your PHP setup.

To test your PHP setup create a file at /var/www/html/info.php and place the following in the file.

 <?php phpinfo(); ?> 

Once the file is created navigate to the website URL /info.php and ensure the service is working properly. Once you have verified this you must remove this file.

Done! Congratulations you have completed the LAMP setup for CentOS 8. Future tutorials will walk you through hosting multiple websites on a single CentOS 8 instance and much more! Choosing CentOS 7/RHEL 7 and LAMP for your webserver is a solid choice! CentOS 7/RHEL 7 have been around for years and are supported until 2023, which means years of support and proven stability!

Some of the links in this article are "affiliate links", a link with a special tracking code. This means if you click on an affiliate link and purchase the item, we will receive an affiliate commission. The price of the item is the same whether it is an affiliate link or not. Regardless, we only recommend products or services we believe will add value to our readers. By using the affiliate links, you are helping support our Website, and we genuinely appreciate your support.

 

Leave a Reply