How to Install the LAMP Stack on CentOS 7

How to Install the LAMP Stack on CentOS 7

SHORT INTRODUCTION

LAMP stands for Linux Apache MariaDB Php

Step 1: Update the system & Install Apache

$ sudo yum update -y
$ sudo yum install httpd -y

Now, we need to start & enable Apache service –

$ sudo systemctl start httpd
$ sudo systemctl enable httpd

Step 2: Install MariaDB Database

Now, we need to install & start MariaDB service –

$ sudo yum install mariadb-server mariadb -y
$ sudo systemctl start mariadb

Now,
Securing MariaDB – Our MariaDB is not secure by default so we need to remove default users,  database & configure other settings : 
 

 
$ sudo mysql_secure_installation

Enter your root password then you will be asked some questions,
you will answer them as shown below :

 
Set root password? [Y/n] Y
New password: Enter your password here
Re-enter new password: repeat your password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Your MariaDB is now secured, Now Enable it by given command:

 
$ sudo systemctl enable mariadb

Step 3 : Install PHP

$ sudo yum install php php-mysql

we need to restart Apache service to work with PHP:

 
$ sudo systemctl restart httpd.service

To test PHP on our CentOs 7 Server, we need to create a file there using a vim editor on the directory ‘/var/www/html/’.

First Install vim Editor & then create our ‘info.php’ file 

 
$ sudo yum install vim -y
$ sudo vim /var/www/html/info.php

A blank text file should be displayed, just copy paste the content below:

phpinfo();
?>

You can the php is working or not by running the command on your browser’s url :

http://ip_address/info.php

Similar Posts