How to Install LAMP Stack on CentOS 8

Introduction

LAMP stands for Linux, Apache, MySQL, and PHP. It is a popular open source web development platform that is used to create dynamic websites and web applications. Installing a LAMP stack on CentOS 8 is a relatively straightforward process. This guide will walk you through the steps necessary to install and configure a LAMP stack on CentOS 8. We will cover the installation of Apache, MySQL, and PHP, as well as the configuration of the web server and database. By the end of this guide, you will have a fully functional LAMP stack running on your CentOS 8 server.

How to Install LAMP Stack on CentOS 8

1. Install Apache Web Server

First, update the system packages:

sudo dnf update

Then, install the Apache web server:

sudo dnf install httpd

Once the installation is complete, start the Apache service and enable it to start on boot:

sudo systemctl start httpd

sudo systemctl enable httpd

2. Install MariaDB Database Server

Install the MariaDB server and client packages:

sudo dnf install mariadb-server mariadb

Once the installation is complete, start the MariaDB service and enable it to start on boot:

sudo systemctl start mariadb

sudo systemctl enable mariadb

Secure the MariaDB installation by running the mysql_secure_installation script:

sudo mysql_secure_installation

3. Install PHP

Install the PHP packages:

sudo dnf install php php-mysqlnd

Once the installation is complete, restart the Apache web server for the changes to take effect:

sudo systemctl restart httpd

You can now test if PHP is working correctly by creating a test PHP file in the web root directory:

sudo vi /var/www/html/info.php

Add the following lines to the file:

Save and close the file.

Now, open your web browser and access the URL http://your-server-ip/info.php. You should see the PHP information page.

Congratulations! You have successfully installed the LAMP stack on your CentOS 8 server.
[ad_1]

Introduction

The LAMP stack is a set of open-source software used for web application development. It consists of a Linux operating system, an Apache HTTP server, the MySQL database management system, and PHP programming language.

In this tutorial, learn how to install the LAMP stack on CentOS 8.

How to install LAMP stack on CentOS 8.

Prerequisites

  • A server running CentOS 8 Linux
  • A terminal window/command line (Search > terminal)
  • A user account with sudo or root privileges
  • The yum and RPM package managers, included by default

Follow the installation steps outlined below and install the required software in the specified order. As this guide is for CentOS 8 users, it skips the first layer of the stack (the Linux operating system), presuming it has already been installed.

Step 1: Update System Software Packages

Open a terminal window and update the package repository before installing new software:

sudo yum update

Step 2: Install Apache

1. Install Apache Web Services with the command:

sudo yum -y install httpd
Apache successfully installed on CentOS 8 server

2. Then, start the Apache service by running:

sudo systemctl start httpd.service

3. To verify Apache is running, open a web browser and navigate to the server’s public IP address. It should display the Apache Test Page, as in the image below.

apache is running on centos 8

Step 3: Install MySQL

The third layer of the LAMP stack is MySQL or MariaDB. Both are open-source database management systems used for storing and managing data on your website.

In this example, the tutorial includes a MySQL installation. Alternatively, you can install MariaDB.

1. Start by adding the MySQL repository:

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

2. Check the repository by typing:

sudo yum repolist all |grep mysql | grep enabled

The output should display a list of the different MySQL options available.

output of a list of MySQL repositories

3. Now, install MySQL:

sudo yum --disablerepo=AppStream install -y mysql-community-server
example of installing mysql

4. Then, enable the MySQL service and set it to start on boot:

sudo systemctl start mysqld
sudo systemctl enable mysqld

5. Check whether the service is running properly with the command:

sudo systemctl status mysql

The output should display the service is active (running).

Checking the MySQL status

Step 4: Configure MySQL Security

The next step is to configure the basic MySQL security settings.

1. Start by displaying the temporary MySQL root password:

cat /var/log/mysqld.log | grep -i 'temporary password'

The system displays the temporary MySQL password.

Prompt MySQL for temporary password to configure security.

2. Next, run the command:

sudo mysql_secure_installation

Provide the MySQL root password received in the previous step.

3. Then, enter and re-enter a new password, making sure it meets the standards for password strength.

4. After updating the password, you are prompted again to change the root password. To do so, type y and hit Enter.

5. The output displays the estimated strength of the password. Press y to continue with the password provided.

Answer the rest of the questions with y and Enter:

  • Remove anonymous users? (y)
  • Disallow root login remotely? (y)
  • Remove test database and access to it? (y)
  • Reload privilege tables now? (y)

With this, MySQL is secured.

Output displaying you have successfully secured the MySQL database.

Step 5: Install PHP and Supporting Modules

Set up the final layer by installing the PHP programming language and the supporting modules for phpMyAdmin:

sudo yum -y install php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd wget upzip
PHP installed on CentOS 8 as part of the lamp stack

Then, enable the PHP module to work with Apache by restarting the webserver:

sudo systemctl restart httpd.service

Step 6: Adjust the Firewall

If you have firewalld set up on CentOS, you need to adjust the configuration to allow Apache connections.

1. Open the firewall for HTTP traffic with the command:

sudo firewall-cmd --permanent --zone=public --add-service=http

2. Next, adjust it to allow HTTPS traffic as well:

sudo firewall-cmd --permanent --zone=public --add-service=https

3. Restart the firewall for the changes to take place:

sudo firewall-cmd --reload

4. Check to verify HTTP and HTTPS routes are now permanently open by running:

sudo firewall-cmd --permanent --list-all

The output should display http and https in the list of services.

List open firewall routes

Step 7: Test PHP with Apache

Apache creates a web root file in the default website directory /var/www/html/. To check whether PHP is set up properly by running a test from this directory.

1. Create a info.php file inside the directory:

sudo vim /var/www/html/info.php

2. Then, add the following content:

<?php

phpinfo ();

?>

3. Save and exit the file.

4. Now, verify if PHP is working correctly. Open a web browser and navigate to the URL (replacing ip_address with the public IP of the server):

http://ip_address/info.php

The browser should display the content, as in the image below.

verification of PHP installation on centos 8

Conclusion

You should now have a working installation of LAMP Stack on your CentOS 8 system.

Next, explore other stack alternatives such as the XAMPP stack or the MEAN stack.

[ad_2]

How to Install LAMP Stack on CentOS 8

LAMP stands for Linux, Apache, MySQL, and PHP. It is a popular open-source web development platform that is used to create dynamic websites and web applications. In this tutorial, we will show you how to install the LAMP stack on CentOS 8.

Prerequisites

  • A server running CentOS 8.
  • A root user or a user with sudo privileges.

Step 1: Install Apache

The first step is to install Apache web server. You can install it with the following command:

sudo dnf install httpd

Once the installation is complete, start the Apache service and enable it to start at boot time with the following command:

sudo systemctl start httpd
sudo systemctl enable httpd

You can check the status of the Apache service with the following command:

sudo systemctl status httpd

Step 2: Install MySQL

Next, you will need to install MySQL server. You can install it with the following command:

sudo dnf install mysql-server

Once the installation is complete, start the MySQL service and enable it to start at boot time with the following command:

sudo systemctl start mysqld
sudo systemctl enable mysqld

You can check the status of the MySQL service with the following command:

sudo systemctl status mysqld

Step 3: Install PHP

Next, you will need to install PHP. You can install it with the following command:

sudo dnf install php php-mysql

Once the installation is complete, restart the Apache service to apply the changes:

sudo systemctl restart httpd

Step 4: Test the LAMP Stack

At this point, the LAMP stack is installed and configured. You can test it by creating a test PHP file in the Apache document root directory:

sudo nano /var/www/html/info.php

Add the following lines:

<?php
phpinfo();
?>

Save and close the file. Then, open your web browser and type the URL http://your-server-ip/info.php. You should see the PHP information page:

Install LAMP Stack on CentOS 8

Congratulations! You have successfully installed the LAMP stack on CentOS 8.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00