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.
Đang xem: Lamp on centos 7
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:
In LAMP, Linux serves as the server’s operating system that handles all the commands on the machine. We’ll be using the CentOS 7 distribution in this tutorial.
Without further ado, let’s learn how to install LAMP on CentOS 7.
3 Steps to Install LAMP on CentOS 7
We’ll divide Apache, MySQL, and PHP installations into different parts to help you understand them better. However, before we dive into the steps, there are a couple of essentials you should know about.
Prerequisites
First of all, make sure that your server already has CentOS 7 installed. At darkedeneurope.com, you can choose the operating system on the VPS hosting plan.
To access your server, you can use terminal in Linux and macOS, or Putty in Windows. For more information, read on how to establish a server connection using your SSH details.
Xem thêm: How To Create A Blog In Php And Mysql Database ? How To Create A Blog In Php And Mysql Database
Once you have gained access, you have to clean all the cache and update yum (default package-management utility for CentOS) This is to remove old packages on CentOS and get the latest version:
sudo yum clean allsudo yum update
1. Install Apache
You can easily install Apache using the yum package. On your SSH client, enter:
sudo yum install httpd -yAfter that, activate your Apache server by typing the following command:
sudo systemctl start httpd.serviceIf the installation and activation were successful, you will get this result when you visit the server’s IP address:
2. Install MySQL (MariaDB) Server
MariaDB is the most popular MySQL fork that is free and open source. The command to install the database is as follows:
sudo yum install mariadb-server mariadb -yNow, let’s start the MariaDB service:
sudo systemctl start mariadbOnce installed, we must secure MariaDB by executing this security command:
sudo mysql_secure_installationWhen prompted for a password, you simply hit Enter to leave it blank or type in new password.
After that, follow the instructions to set up your password. Lastly, the script will ask you to configure several security measures, including:
Remove anonymous users?Disallow login remotely?Remove test database and access to it?Reload privilege tables now?
When you are done with the process, it will send you this message:
Cleaning up… All done! If you”ve completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
3. Install PHP
First, you have to install yum-utils and enable EPEL (Extra Packages for Enterprise Linux) repository:
sudo yum install epel-release yum-utilsThen, download and install remirepo:
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpmEnable it:
sudo yum-config-manager –enable remi-php73To install PHP, use the following command:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlndIf you want to check the version, type php -v and you should get this result:
sudo systemctl restart httpd.serviceThe next step is to test PHP processing. To do that, we need to create info.php file and put it on the default PHP directory (/var/www/html). You can use nano editor for this:
sudo nano /var/www/html/info.phpThen, insert this code inside:
Use CTRL+X to exit and save the file. The last thing is to check your server by visiting the info.php URL:
http://your.ip.address/info.php
The page should look like this:
Good job! This means PHP is installed and running on your server. You have successfully installed LAMP on CentOS 7.
Conclusion
LAMP stack is an essential set of programs for web development. It consists of Linux, Apache, MySQL, and PHP. They work hand in hand to help you manage a server or VPS.
Our tutorial has shown you how to install LAMP stack on CentOS 7. Here’s our brief summary of all the steps.
Make sure your server runs on CentOS 7. Then, clean the cache and update to the latest packages.Install Apache and then check if it’s already enabled on your server.Install MySQL with MariaDB and run a security command to secure your database.