LAMP is an open-source web solution stack that is used in web application development. It stands for Linux (L), Apache (A), MySQL (M), and PHP (P). Apache server processes and serves web requests via HTTP. MySQL is a database management system that stores information in a structured format. PHP is a backend scripting language that get information from the database and hand over the processed content to Apache for display.
Today’s post is about how to install LAMP stack on the CentOS system.
Note: The method shown here has been tested on CentOS 8.
Step 1: Install Apache
Apache is available in the default CentOS repositories. Therefore, you can simply install it using the Yum package manager. Here is the command to install Apache on CentOS:
$ sudo yum install httpd
As you are running the above command as sudo, therefore you will be required to enter the sudo password. After that the Terminal might prompt you for confirmation, hit y to confirm, and Apache will be installed on your system.
After the installation is finished, use the command below to start the Apache service:
$ sudo systemctl start httpd.service
Then use the command below to verify the status of the service:
$ sudo systemctl status httpd.service
The output below verifies that the Apache HTTP server has been started and running.
You can also verify the working of the Apache server by visiting the address below:
http://ip-address
If everything is functioning well, the following default web page should appear on your browser.
Step 2: Install MySQL (MariaDB)
Now in this step, we will install the MariaDB database (drop-in replacement of MySQL). It is also available in the default CentOS repositories, so we can simply install it using the command below in the Terminal:
$ sudo yum install mariadb-server mariadb
The Terminal might prompt you for confirmation. Press y to confirm. Now the installation of mentioned packages will be started on your system.
After the installation is finished, use the command below to start the MariaDB service:
$ sudo systemctl start mariadb.service
To verify the status of the service, use the command below:
$ sudo systemctl status mariadb.service
The output below verifies that MariaDB has been started and running.
Step 3: Install PHP
PHP can also be installed using the CentOS Yum package manager. Here is the command to install the PHP packages:
$ sudo yum install php php-mysqlnd.x86_64
The Terminal might prompt you for confirmation. Press y to confirm. Now the installation of mentioned packages will be started on your system.
Now to make the Apache web server function with PHP, restart the Apache web server:
$ sudo systemctl restart httpd.service
Now to verify that your system is configured properly for PHP, create a file named info.php at /var/www/html/.
$ sudo nano /var/www/html/info.php
Add the below line in the info.php file:
<?php phpinfo(); ?>
Then save and close the file.
Now access the following address in your web browser:
http://ip-address/info.php
If everything is working well, you should see the following default web page on your screen.
After verifying that PHP is working well, you can remove the info.php file using the command below:
$ sudo rm /var/www/html/info.php
In this post, you have learned how to install the LAMP stack on the CentOS system. If are using another Linux distribution, visit how to install LAMP stack on Debian, Red Hat, and Rocky Linux.