We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

How to Install LAMP Stack Apache MySQL/MariaDB PHP on CentOS 8

How to Install LAMP Stack Apache MySQL/MariaDB PHP on CentOS 8. In this guide you are going to learn how to install and setup Apache, PHP, MySQL on CentOS 8.

This setup is tested on Google Cloud and it works the same on AWS, DigitalOcean or any cloud hosting services or any VPS or Dedicated servers.

Prerequisites

If you are using Google Cloud you can follow these setps otherwise you can skip them.

  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance with CentOS 8

Step 1: Update Software Packages

You can start the setup by updating the packages to the latest versions using the following command.

sudo yum update

Step 2: Install Apache on CentOS 8

Installing Apache in CentOS is pretty straight forward which is known as httpd. Run the following command to install.

sudo yum install httpd

Once the installation is completed, enable and start the Apache service.

sudo systemctl enable httpd
sudo systemctl start httpd

Step 3: Configure Firewall

If your server is protected by the firewall and you haven’t opened the HTTP and HTTPS ports. Enable them with the following command.

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

Now you can verify Apache installation. Every process in Apache is managed with the systemctl command. Verify the installation of Apache with the following command.

sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
    Active: active (running) since Mon 2019-11-11 09:41:12 UTC; 5s ago
      Docs: man:httpd.service(8)
  Main PID: 19440 (httpd)
    Status: "Started, listening on: port 80"
     Tasks: 213 (limit: 9584)
    Memory: 24.5M
    CGroup: /system.slice/httpd.service
            ├─19440 /usr/sbin/httpd -DFOREGROUND
            ├─19441 /usr/sbin/httpd -DFOREGROUND
            ├─19442 /usr/sbin/httpd -DFOREGROUND
            ├─19443 /usr/sbin/httpd -DFOREGROUND
            └─19444 /usr/sbin/httpd -DFOREGROUND
 Nov 11 09:41:12 instance-1 systemd[1]: Starting The Apache HTTP Server…
 Nov 11 09:41:12 instance-1 httpd[19440]: Server configured, listening on: port 80
 Nov 11 09:41:12 instance-1 systemd[1]: Started The Apache HTTP Server.

Step 4: Install MySQL/MariaDB Database on CentOS 8

MariaDB is a better alternative for MySQL, so we can use MariaDB instead of MySQL.

sudo yum install mariadb-server mariadb -y
sudo systemctl enable mariadb
sudo systemctl start mariadb

You can verify the status of MariaDB installation using the following command.

sudo systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
    Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
    Active: active (running) since Mon 2019-11-11 09:42:45 UTC; 47s ago
      Docs: man:mysqld(8)
            https://mariadb.com/kb/en/library/systemd/
   Process: 22519 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
   Process: 22385 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
   Process: 22361 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Main PID: 22487 (mysqld)
    Status: "Taking your SQL requests now…"
     Tasks: 30 (limit: 9584)
    Memory: 86.3M
    CGroup: /system.slice/mariadb.service
            └─22487 /usr/libexec/mysqld --basedir=/usr

Secure the MariaDB server with the mysql_secure_installation command.

mysql_secure_installation
MySQL Secure Installation

Follow the prompts and create a new password for the root user and complete the process.

Step 5: Install PHP on CentOS 8

Finally you can install PHP, by default CentOS ships with PHP 7.2. So you can install PHP using the following command.

sudo yum install -y php php-mysqlnd

Restart Apache.

sudo systemctl restart httpd

Step 6: Verify the LAMP setup

Create a new file to output the PHP info.

Install the nano editor which is the easy editor to create and edit a new file.

sudo yum install nano -y

Create a new file with the name info.php

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

Paste the following code in the editor and save the file.

<?php phpinfo();

Hit CTRL + X followed by Y and Enter to save and exit the file.

Now open your browser and point it to your external IP address of your server followed by info.php in the URL.

http://IP_Address/info.php
LAMP setup on CentOS 8

You will see the PHP information which indicates you have installed and configured Apache, MariaDB and PHP on your CentOS 8 server.

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

Conclusion

Now you have learned how to install Apache, MySQL and PHP LAMP stack on CentOS 8.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Cart

Your Cart is Empty

Back To Shop