
LAMP is a common web stack for web service that stands for Linux, Apache, MySQL/MariaDB and PHP and it is one of the most popular web service solutions in Linux.
In this guide, we will install a LAMP stack on a CentOS 7 server.
Notice: You must execute commands with root permission. If you don’t have root permission, you may start commands with “sudo”.
Prepare CentOS to install LAMP
Step1: set your server hostname.
Step 2: Update you Linux date and time. You can use the following command to set time and date:
ntpdate time.windows.com
Step 3: Update your CentOS using following command:
yum -y update
Step 4: Reboot your Linux:
reboot
Install LAMP stack on CentOS 7
Install apache
First install Apache web server. You can use the following command:
yum install -y httpd
To restart Apache web server, use bellow command:
systemctl start httpd.service
Add Apache service to startup service list to start it automatically at boot time:
systemctl enable httpd.service
Now you can test your Apache by opening your browser and see your Public IP address (or domain). You will see the default CentOS 7 Apache web page, which is there for informational and testing purposes. It should look something like this:
If you face any error, use the bellow commands to add rules to your firewall:
sudo firewall-cmd --zone=public --add-service=http --permanent
Reload firewall using the following command:
sudo firewalld-cmd --reload
Install and configure MariaDB
Install MariaDB package using below command:
yum install -y mariadb-server mariadb
Start MariaDB with the following command:
systemctl start mariadb
Add MariaDB to startup services:
systemctl enable mariadb
To remove some insecure defaults, run MySQL secure installation:
mysql_secure_installation
Enter your MariaDB password twice and answer remaining questions. It’s recommended to answer all other questions with “y”.
Install PHP
Download and install PHP using the below command:
yum install -y php php-mysql
Restart the Apache service in order to work with PHP with the command below:
systemctl restart httpd.service
PHP installation has been completed. If you need any further module, you can see available domules using the bellow command:
yum search php-
After finding your module, you can install modelu using Yum command. For example:
yum -y install php-mbstring.x86_64
Now to test your PHP, create a file named “info.php” in the /var/www/html/ location using command below:
nano /var/www/html/info.php
Append the following PHP code to it then save and exit (Ctrl+O , Ctrl+X)
Service Test
You can test your service by opening your browser and see your Public IP address or domain with /info.php at its end, the result should be something like the picture below:
Congratulations! In this article, you have learnt how to install LAMP stack on CentOS 7.
If you are facing any problem with the installation, feel free to comment here. We will help you to solve the issue.