Setup LAMP on CentOS 7: Complete Guide

To set up a LAMP environment in CentOS7, you need to install Apache, MySQL, and PHP. Here are the specific steps for building a LAMP environment in CentOS7:

  1. Install Apache.

Open the terminal and execute the following command to install Apache:

sudo yum install httpd

Start Apache and enable it to start automatically on boot.

sudo systemctl start httpd
sudo systemctl enable httpd

Confirm if Apache is successfully installed by opening a browser and entering http://localhost. If you see the default Apache page, then the installation was successful.

  1. Install MySQL

Run the following command to install MySQL.

sudo yum install mysql-server

Start MySQL and set it to start up automatically.

sudo systemctl start mysqld
sudo systemctl enable mysqld

Run the mysql_secure_installation command to set the root password for MySQL and other security options.

  1. Install PHP.

Run the following command to install PHP and its related extensions:

sudo yum install php php-mysql

After installation is complete, restart Apache.

sudo systemctl restart httpd
  1. Test the LAMP environment.

Create a PHP file in the default website directory of Apache (/var/www/html), such as test.php, with the following content:

<?php
phpinfo();
?>

Accessing http://localhost/test.php in the browser and seeing the PHP information page indicates that the LAMP environment has been successfully set up.

You have successfully set up a LAMP environment in CentOS 7.

bannerAds