How to install LAMP stack on CentOS 8
Learn how to install the LAMP stack (Linux, Apache, MySQL, and PHP) on a CentOS 8server in this tutorial. Follow the step-by-step guide to set up a powerful and flexible web development environment on your server.
In this tutorial, we will provide you with a detailed guide on how to install the LAMP stack on an CentOS 8 server. The LAMP stack consists of four components: Linux, Apache, MySQL, and PHP. These tools are used together to host web applications written in PHP, making it a powerful and flexible solution for web development.
Installing the LAMP stack on an CentOS server is a relatively straightforward process, but it does require some technical knowledge and experience with the command line. We will walk you through each step of the process to ensure that you are able to set up your LAMP stack successfully.
To run a LAMP web server, we're going to need a server with CentOS 8 installed as its operating system. You can grab yourself $200 free credit from Digital Ocean to get a virtual machine if you haven't got a server already!
Although it isn't required, we highly recommend you set up some basic firewall rules along with a non-root user. Take a look at our basic CentOS 8 server setup guide on how to do that.
During this guide, we will mention
my_domain which you'll need to replace with your actual domain name.
Installing LAMP (Linux, Apache, MySQL, PHP) on CentOS 8 is a multi-step process that involves installing and configuring each component individually. Here is a detailed guide on how to set up LAMP on CentOS 8:
###Install Apache Web Server:
Open a terminal and run the following command to install Apache:
sudo dnf install httpd
Once the installation is complete, start the Apache service by running:
sudo systemctl start httpd
To make sure Apache starts automatically on boot, run:
sudo systemctl enable httpd
Install MySQL Server:
Run the following command to install MySQL:
sudo dnf install mariadb-server mariadb
Once the installation is complete, start the MySQL service by running:
sudo systemctl start mariadb
To make sure MySQL starts automatically on boot, run:
sudo systemctl enable mariadb
Now, run the following command to secure MySQL installation:
Follow the prompts to set the root password and answer the questions.
Run the following command to install PHP and the necessary modules for running PHP with Apache:
sudo dnf install php php-mysqlnd php-opcache
Once the installation is complete, you will need to configure Apache to use PHP. To do this, open the file
/etc/httpd/conf.d/php.conf and add the following line at the end of the file:
AddType application/x-httpd-php .php
Restart Apache for the changes to take effect:
sudo systemctl restart httpd
Verify the installation:
To verify that LAMP is working properly, create a new file named "info.php" in the /var/www/html/ directory:
sudo nano /var/www/html/info.php
Add the following line to the file:\
<?php phpinfo(); ?>
Save the file and exit.
Open a web browser and navigate to the following URL:
If everything is working correctly, you should see a page displaying information about your PHP installation. That's it, you have successfully installed LAMP stack on your CentOS 8 server.
Congratulation, you should now have a functioning LAMP stack web server with Linux, Apache, MySQL and PHP set up and running. You can now begin building your website and show it off to the world!
You should now go ahead and protect your website with an SSL certificate using Let's Encrypt, we have a guide outlining exactly how to do this!