This blog receives a commission from affiliate partners through the affiliate links that we share with you in our posts. Although we receive a commission for using and linking their products, all our opinions and suggestions are unbiased.
What is LAMP Stack?
LAMP stack is a group of open-source software that is usually installed together to enable a server to host websites and web applications. The acronym represents L for the Linux Operating System, A for Apache Web Server, M for MySQL, and P for PHP. In this tutorial, we will cover how to install the LAMP stack on your CentOS Linux Server.
Also Read: Ubuntu: Install LAMP Stack
Also Read: CentOS: Install LEMP Stack
Start off by installing Apache Web Server with CentOS’s package manager, yum.
sudo yum install httpd
Once the installation is complete we will then start the Apache service.
sudo systemctl start httpd.service
Once the service started successfully you can test if Apache HTTP Server is running by entering your local hostname or IP address in your browser:
If it is working you will see a default test page which indicates that your Apache Web server installation was successful.
The last step you should take to complete your Apache installation is to enable Apache Web server to start on boot:
sudo systemctl enable httpd.service
Install MySQL (MariaDB)
Once our web server is up and running we will go to step number two and install MySQL (MariaDB). MariaDB is a community-developed fork of the MySQL relational database management system.
We will use the yum package manager like in our first step to install MySQL(MariaDB).
sudo yum install mariadb-server mariadb
Once the MariaDB installation has completed then we will start it.
sudo systemctl start mariadb
Once the MySQL database is running, we will then run a simple security script that will remove defaults and lock down access to our database system. Start the script by running the following:
A prompt will ask for your current root password. If you just installed MySQL then you can leave it blank and press enter. The prompt will then ask if you want to set a root password. You can go ahead and enter Y and follow the instructions:
Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. New password: password Re-enter new password: password Password updated successfully! Reloading privilege tables.. ... Success!
You can simply hit Enter on each prompt from here to accept the default values. Once all these steps completed to setup MariaDB then you can go ahead and configure MariaDB to start on boot:
sudo systemctl enable mariadb.service
Once that final configuration completed then your MySQL(MariaDB) database system is configured and setup.
In order to see the available options for PHP modules and libraries, you can run the following:
yum search php-
You will see optional components like the below results:
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library php-cli.x86_64 : Command-line interface for PHP php-common.x86_64 : Common files for PHP php-dba.x86_64 : A database abstraction layer module for PHP applications php-devel.x86_64 : Files needed for building PHP extensions php-embedded.x86_64 : PHP library for embedding in applications php-enchant.x86_64 : Enchant spelling extension for PHP applications php-fpm.x86_64 : PHP FastCGI Process Manager php-gd.x86_64 : A module for PHP applications for using the gd graphics library . . .
After browsing through the packages we can use the yum install command to install php-fpm:
sudo yum install php-fpm
Or if you want to install more than one module you can use the following:
sudo yum install <package1> <package2> …
After PHP installation completes then your LAMP stack is installed and configured.
Test PHP Processing on Your Web Server
We will call a script info.php and save it under the directory called “web root”.
In CentOS the directory is located at /var/www/html/. We will create the info.php file under this location:
sudo vi /var/www/html/info.php
This script will open a blank and then insert the following PHP code inside the file:
<?php phpinfo(); ?>
Once complete save and exit. The next step is to configure the firewall to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd –reload
Once complete we will then type the following in the web browser to test if we can visit the page:
The page returned should look similar to this one below:
If this was successful then your PHP setup and configuration are working. We will then remove the info.php file as it could give unauthorized users information about your server:
sudo rm /var/www/html/info.php
You can recreate the file later if you should require the information again. After all the tests and configurations you have completed the LAMP stack installation on your CentOS server. It is now ready to host websites and web applications.
Chad is an experienced Systems Administrator with exposure to various technologies and enterprise ICT environments. He has a huge passion for Technologies, specifically Linux, Open Source Software, Cloud Computing, DevOps, Software & Web Development, electronics, and IoT technologies.
If you enjoy our articles please support us and make a small contribution: Buy Us A Coffee