Do you want to know how to install LAMP stack on CentOS 7? You have come to the right place! In this article, you will learn about what LAMP stack is and how to install it on your Linux-based server.
What is LAMP ?
LAMP is short for Linux, Apache, MySQL and PHP. It is a stack of applications that work together on a web server to host a website. With that being said, each individual program serves a different purpose.
Install LAMP on CentOS 7
You can mount the disk with CentOS 7.8 Server – 64bit Pre-Installed English with SSH, Python, Pip, Cloud-init, OpenSSL, and VirtIO support. After starting the machine, you can update all the existing repos and packages on the machine by running the following commands:
$sudo yum clean all
sudo yum update -y
1. LAMP Stack: A – install Apache
- Apache is a web server software that manages HTTP requests to deliver your website’s content. You can easily install Apache using the yum package. On your SSH client, enter:
sudo yum install httpd -y
After that, activate your Apache server by typing the following command:
sudo systemctl start httpd.service
Once it’s installed, you can go to the IP address on your web browser and you will see an output similar to this:
If you don’t see the above screen, it’s possible that your firewall is blocking the HTTP traffic. You can use the following commands and try again:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload sudo systemctl enable httpd.service
2. LAMP Stack M: install MySQL (MariaDB)
- MySql is a relational database management system (RDBMS) whose function is to maintain user’s data on a server. First, you have to install yum-utils and enable EPEL (Extra Packages for Enterprise Linux) repository:
sudo yum install mariadb-server mariadb -y
Now, let’s start the MariaDB service:
sudo systemctl start mariadb
Once installed, we must secure MariaDB by executing this security command:
sudo mysql_secure_installation
To increase the security, run the below script, and choose your preferences:
sudo /usr/bin/mysql_secure_installation
3. LAMP Stack P: Install PHP
- PHP is a scripting language for server-side communication. First, you have to install yum-utils and enable EPEL (Extra Packages for Enterprise Linux) repository:
sudo yum install epel-release yum-utils
Then, download and install remirepo:
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Enable it:
sudo yum-config-manager --enable remi-php73
To install PHP, use the following command:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
If you want to check the php version Restart your Apache server to ensure that it’s working with the newly installed PHP:
sudo systemctl restart httpd.service
The next step is to test PHP processing. To do that, we need to create test.php file and put it on the default PHP directory (/var/www/html). You can use vim editor for this enter the script and save it
sudo nano /var/www/html/info.php
Then, insert this code inside press ESC key enter :wq Save it
<?php phpinfo(); ?>
The last thing is to check your server by visiting the test.php URL: http://your.ip.address/info.php