In this tutorial we’ll learn how to install LAMP on CentOS 7. We will also install and configure its prerequisites. LAMP is a simple software bundle made of 4 components, Linux, Apache, MySQL or MariaDB and PHP.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install LAMP on CentOS 7
Step 1. First, ensure your system is fully up-to-date by running the following:
yum -y update
Step 2. Installing and configuring Apache.
Install Apache by running the following command:
yum install httpd
After the installation is complete, you should enable Apache to start automatically upon system boot. You can do that with the following command:
systemctl start httpd.service systemctl enable httpd.service
We can now verify Apache is working by opening your browser and entering the URL http://your-server’s-address, (e.g. http://192.168.77.1).
Step 3. Installing and configuring MariaDB.
Now that we have a web server, we need to install MariaDB, a database management system, to store and manage the data for our site. You can install this easily by running the following:
yum install mariadb-server mariadb
Start the MariaDB service with the following command:
systemctl start mariadb.service systemctl enable mariadb.service
MariaDB needs some security modifications to help protect your databases from unauthorized access. Run the following command:
Follow the prompts as below:
- Would you like to setup VALIDATE PASSWORD plugin? press Enter here for No
- Please set the password for root here. New password: Type a secure password here then press Enter
- Re-enter new password: Re-type the secure password here then press Enter
- Remove anonymous users? (Press y|Y for Yes, any other key for No) : press y and then Enter here
- Disallow root login remotely? (Press y|Y for Yes, any other key for No) : press y and then Enter here
- Remove test database and access to it? (Press y|Y for Yes, any other key for No) : press y and then Enter here
- Reload privilege tables now? (Press y|Y for Yes, any other key for No) : press y and then Enter here
Step 4. Installing and configuring PHP 7.
Install PHP and related packages using the following command:
yum install php php-mysql php-gd
If you want to install all php modules, enter the command yum install php* -y and restart the httpd service.
Next, create a test PHP file in the following directory. We use nano, but you may use your preferred text editor:
Enter the following inside the file and save it:
<?php phpinfo(); ?>
Finally, restart the Apache server by typing:
systemctl restart httpd.service
Now, if you navigate to this page: http://your_server_ip_address/info.php in your web browser, you will see the following page showing your current PHP configuration:
Congratulation’s! You have successfully configured LAMP Stack on your CentOS 7 server.