How to install LAMP Stack in Linux

1
577

LAMP

LAMP is an acronym stands for”Linux, Apache server, Mysql/mariadb, and Php“. Which is common server configuration used for many web applications.

In this article we will known about the installation of LAMP in Linux.

Apache Installation

Apache is open source and well known web server. The installation of Apache web server is simple. we can install Apache web server(httpd service) by using yum command as follows

[root@localhost ~]# yum –y install httpd

We can check the installation of Apache Web Server as follows

apache check

Now Allow Apache web server through the firewall.

[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
[root@localhost ~]# firewall-cmd --permanent --add-port=443/tcp

Then reload the firewall by using the command as follows

[root@localhost ~]# firewall-cmd --reload

Now enable and start the httpd service as follows

[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl start httpd

We can get the Apache Web Server home page at http://ipaddress.

httpd homepage

MariaDB Installation

MariaDB is a drop in replacement for Mysql. The installation of MariaDB is a very simple , we can install it by using the yum command as follows.

[root@localhost ~]# yum -y install mariadb-server mariadb

Now we can start the MariaDB and make it can start at boot time by using the following commands

[root@localhost ~]# system-ctl enable mariadb
[root@localhost ~]# system-ctl start mariadb

By default the root password for MariaDB is empty.so now we have to set the password for the root in MariaDB.

[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

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

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

we can access the databases by using the command mysql as foollows

[root@localhost ~]# mysql -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

PHP Installation

Php is a server side scripting language designed for web servers.It stands for recursively php:Hypertext Preprocessor

We can install php as follows

[root@localhost ~]# yum -y install php
Loaded plugins: fastestmirror, langpacks
base                                                                                     | 3.6 kB  00:00:00
extras                                                                                   | 3.4 kB  00:00:00
updates                                                                                  | 3.4 kB  00:00:00
(1/4): base/7/x86_64/group_gz                                                            | 155 kB  00:00:05
(2/4): extras/7/x86_64/primary_db                                                        | 160 kB  00:00:08
(3/4): updates/7/x86_64/primary_db                                                       | 6.4 MB  00:00:21
(4/4): base/7/x86_64/primary_db                                                          | 5.3 MB  00:00:24
Determining fastest mirrors
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-36.1.el7_2.1 for package: php-5.4.16-36.1.el7_2.1.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.4.16-36.1.el7_2.1 for package: php-5.4.16-36.1.el7_2.1.x86_64
--> Running transaction check
---> Package php-cli.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
---> Package php-common.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
--> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-36.1.el7_2.1.x86_64
--> Running transaction check
---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                  Arch                 Version                              Repository             Size
================================================================================================================
Installing:
 php                      x86_64               5.4.16-36.1.el7_2.1                  updates               1.4 M
Installing for dependencies:
 libzip                   x86_64               0.10.1-8.el7                         base                   48 k
 php-cli                  x86_64               5.4.16-36.1.el7_2.1                  updates               2.7 M
 php-common               x86_64               5.4.16-36.1.el7_2.1                  updates               563 k

Transaction Summary
================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 4.7 M
Installed size: 17 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/libzip-0.10.1-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for libzip-0.10.1-8.el7.x86_64.rpm is not installed
(1/4): libzip-0.10.1-8.el7.x86_64.rpm                                                    |  48 kB  00:00:05
Public key for php-5.4.16-36.1.el7_2.1.x86_64.rpm is not installed            ]  0.0 B/s | 142 kB  --:--:-- ETA
(2/4): php-5.4.16-36.1.el7_2.1.x86_64.rpm                                                | 1.4 MB  00:00:07
(3/4): php-common-5.4.16-36.1.el7_2.1.x86_64.rpm                                         | 563 kB  00:00:08
(4/4): php-cli-5.4.16-36.1.el7_2.1.x86_64.rpm                                            | 2.7 MB  00:00:15
----------------------------------------------------------------------------------------------------------------
Total                                                                           309 kB/s | 4.7 MB  00:00:15
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzip-0.10.1-8.el7.x86_64                                                                   1/4
  Installing : php-common-5.4.16-36.1.el7_2.1.x86_64                                                        2/4
  Installing : php-cli-5.4.16-36.1.el7_2.1.x86_64                                                           3/4
  Installing : php-5.4.16-36.1.el7_2.1.x86_64                                                               4/4
  Verifying  : php-common-5.4.16-36.1.el7_2.1.x86_64                                                        1/4
  Verifying  : php-cli-5.4.16-36.1.el7_2.1.x86_64                                                           2/4
  Verifying  : libzip-0.10.1-8.el7.x86_64                                                                   3/4
  Verifying  : php-5.4.16-36.1.el7_2.1.x86_64                                                               4/4

Installed:
  php.x86_64 0:5.4.16-36.1.el7_2.1

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7  php-cli.x86_64 0:5.4.16-36.1.el7_2.1  php-common.x86_64 0:5.4.16-36.1.el7_2.1

Complete!

We can check the installation of php by using the command rpm -qa|grep php

Lamp php check

Now install php modules by using the yum command as follows

[root@localhost ~]# yum install php-mysql -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
--> Processing Dependency: php-pdo(x86-64) = 5.4.16-36.1.el7_2.1 for package: php-mysql-5.4.16-36.1.el7_2.1.x86_64
--> Running transaction check
---> Package php-pdo.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                  Arch                  Version                            Repository              Size
================================================================================================================
Installing:
 php-mysql                x86_64                5.4.16-36.1.el7_2.1                updates                 99 k
Installing for dependencies:
 php-pdo                  x86_64                5.4.16-36.1.el7_2.1                updates                 97 k

Transaction Summary
================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 197 k
Installed size: 424 k
Downloading packages:
(1/2): php-pdo-5.4.16-36.1.el7_2.1.x86_64.rpm                                            |  97 kB  00:00:03
(2/2): php-mysql-5.4.16-36.1.el7_2.1.x86_64.rpm                                          |  99 kB  00:00:03
----------------------------------------------------------------------------------------------------------------
Total                                                                            55 kB/s | 197 kB  00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-pdo-5.4.16-36.1.el7_2.1.x86_64                                                           1/2
  Installing : php-mysql-5.4.16-36.1.el7_2.1.x86_64                                                         2/2
  Verifying  : php-mysql-5.4.16-36.1.el7_2.1.x86_64                                                         1/2
  Verifying  : php-pdo-5.4.16-36.1.el7_2.1.x86_64                                                           2/2

Installed:
  php-mysql.x86_64 0:5.4.16-36.1.el7_2.1

Dependency Installed:
  php-pdo.x86_64 0:5.4.16-36.1.el7_2.1

Complete!

Enjoy LAMP Stack in Linux!

Comments

comments

1 COMMENT