Install LAMP stack on CentOS

LAMP stack stands for the set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is widely used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on CentOS.

Prerequisites

Before you start to install LAMP stack on CentOS 7. You must have the non-root user account on your server with sudo privileges.

1. Install Apache

In CentOS and RHEL Apache service is known as httpd. As Apache repository is available if CentOS core repositories, installation is pretty easy.

To install Apache on CentOS enter following command

sudo yum install httpd

Once You install Apache start and enable service by typing following in terminal.

sudo systemctl start httpd
sudo systemctl enable httpd

Confirm the status of Apache service by running following command

sudo systemctl status httpd

Enter CTRL+c to exit.

2. Install MariaDB

Now you are going to install MariaDB on your server. To install type following:

sudo yum install mariadb-server

After installing MariaDB you should start and enable MariaDB service by running the following command.

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Check the status of MariaDB service by typing

sudo systemctl status mariadb.service

The Installer generates the temporary password for MariaDb and saves it inside a file to check the password inside file enter following command

grep "A temporary password" /var/log/mysqld.log  | tail -n1

[Some text hidden] A temporary password is generated for [email protected]: Eif;=GPCD88#

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

Enter CTRL+c to exit

3. Install PHP

CentOS does not ship with PHP 7.2 in its core repositories. Here we are going to use the Remi repository to install PHP 7.2.

Enter the following command to add Remi repository on CentOS

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Now you should enable remi-php72 repository, to do so type:

sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72

Install PHP and some of its required extensions by typing

sudo yum install php php-common php-gd php-curl php-mysql

Now restart Apache by using the following command

sudo systemctl restart httpd

Test PHP

Now you should create info.php file to test php to do so type following.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/info.php or http://localhost/info.php in your browser.

Conclusion

You have successfully learned to install LAMP stack on CentOS 7. If you have any queries regarding this please don’t forget to comment below.

Install LAMP stack on Ubuntu

LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on Ubuntu.

Prerequisites

Before you start to install LAMP stack on Ubuntu 18.04. You must have the non-root user account on your server/desktop with sudo privileges.

1. Install Apache

First, you will need to update the package manager index by typing

sudo apt update

Now install Apache by running following command

sudo apt install apache2

Confirm the installation of Apache by using the following command

sudo systemctl status apache2

If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/

2. Install MariaDB

Update apt package manager index by typing following command

sudo apt update

Now you can install MariaDB by running following command

sudo apt install mariadb-server mariadb-client

Check the status and confirm installation by typing following command

sudo systemctl status apache2

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

3. Install PHP

To install PHP you should first update package manager index then you will install PHP.

Update apt package manager index by typing

sudo apt update

Install PHP and some of its common extensions by typing

sudo apt install php php-common php-mysql php-gd php-cli

After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installtion.

Conclusion

You have successfully learned how to install LAMP stack on Ubuntu 18.04. If you have any queries regarding this please don’t forget to comment below.