In this tutorial, we will explain How to install LAMP Stack on CentOS

LAMP is an archetypal model of web service stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system, and the PHP programming language.

Prerequisites

You will need:

  • A VPS running CentOS
  • And to update your system:

sudo yum update

Step 1 – Install Apache

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows.

You can install Apache by following this command:

yum install httpd

Note: When asks for prompt type Y and hit Enter.

After, you need to start and enable the apache:

systemctl start httpd.service

systemctl enable httpd.service

Step 2 – Install MariaDB

Now you need to install MariaDB. We will need MariaDB to store information of the website.

To install it, run this command:

yum install mariadb-server mariadb

After, you need to start and enable it:

systemctl start mariadb

systemctl enable mariadb.service

Now its time to secure the installation.

mysql_secure_installation

You will be asked for a password, so just hit Enter.

After, you will be asked a series of questions.

  • Set root password? [Y/n]

Type y if you want to set.

  • Remove anonymous users? [Y/n]

Type y if you want to remove.

  • Disallow root login remotely? [Y/n]

Type y if you want to disallow.

  • Remove test database and access to it? [Y/n]

Type y to remove.

  • Reload privilege tables now? [Y/n]

Type y to reload privileges.

Step 3 – Install PHP

PHP is a popular general-purpose scripting language that is especially suited. To install PHP and MySQL extension you need to run the following command:

yum install php php-mysql

Restart web service to get effects:

systemctl restart httpd.service

Step 4 – Test PHP

You need to test PHP if is working. You can do it by running the following command:

echo “<?php phpinfo();” > /var/www/html/phpinfo.php

Now go to your browser and open this url http://youripaddress/phpinfo.php to see PHP configuration information.

You have successfully installed LAMP Stack in CentOS.

Enjoy.