LAMP (Linux Apache, Mysql, PHP ) on cent 7

LAMP (Linux Apache, Mysql, PHP ) on cent 7 


LAMP (Linux Apache, Mysql, PHP ) is a set of open source software allow to host dynamic web sites. 

Steps to install Apache, Mysql, PHP on cent OS version 7. 

let's start with Apache 



# yum install httpd 

# systemctl start httpd.service 

    check the status of httpd 

# systemctl status httpd



After starting httpd service web server will be accessible via http://localhost if you are NOT able to access then check your firewall related settings and allow web service request through port 80. 

To check allowed port service on firewall
firewall-cmd --list-all

[root@techitadmin ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: ssh dhcpv6-client http
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

To enable httpd from firewall and allow port 80 

[root@techitadmin ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp

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

[root@techitadmin ~]# firewall-cmd --list-all
  public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: ssh dhcpv6-client http
  ports: 80/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:

  rich rules:

We can also check all the allowed ports status using a program utility called "nmap"

#nmap -sT 192.168.*.* 

[root@techitadmin ~]# nmap -sT 192.168.*.*

Starting Nmap 6.40 ( http://nmap.org ) at 2018-12-27 15:28 IST
Nmap scan report for techitadmin (192.168.*.*)
Host is up (0.0014s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds

[root@techitadmin ~]#


 if nmap is not installed you may install 

#yum install nmap 

To find your web server IP address :- 
[root@techitadmin ~]# ip addr show enp0s3 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

192.168.*.* 

change your Ethernet interface name as accordingly as in this case its "enp0s3 " 

now let's move to the next step and install mySQL database software for our dynamic web side which will help us to store all the crucial data related to web site, MySQL is a relational database management system helps to insert and retrieve data. 

Installation command:- 

[root@techitadmin ~]# yum install mariadb-server mariadb

After the successfully installation of above package run this :

[root@techitadmin ~]# systemctl start mariadb

To remove some of dangerous default and lock down to access our database system run this :- 

[root@techitadmin ~]# 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):

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] Y
 ... 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] Y
 ... Success!

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] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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

Reload privilege tables now? [Y/n] Y
 ... 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!

[root@techitadmin ~]#

To enable your database on boot by default 
[root@techitadmin ~]# systemctl enable mariadb.service

Next step is to install PHP :- 

PHP stands for Hypertext processor is a program to process your dynamic content and display on screen. 

Command to install php
 [root@techitadmin ~]# yum install php php-mysql

To check the installed package status 


[root@techitadmin ~]# yum info php
Installed Packages
Name        : php
Arch        : x86_64
Version     : 5.4.16
Release     : 46.el7
Size        : 4.4 M

Repo        : installed

To run and test PHP 
[root@techitadmin html]# vi /var/www/html/info.php

Write this code in info.php file 
<?php
     phpinfo();
?>

Now test and run this phpinfo in your browser 

 http://localhost/info.php

This kind above output is result of successful working PHP.


PHP version 7 installation on cent OS 7

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum install yum-utils
# yum-config-manager --enable remi-php70 
if you wish to install PHP 7.1 or PHP 7.2 on CentOS 7, just enable it as shown
# yum-config-manager --enable remi-php71   ( PHP 7.1 )
# yum-config-manager --enable remi-php72   ( PHP 7.2 )
Now install PHP 7 with all necessary modules 
# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo 
To check the version of installed PHP 
php -v 

Complete!
[root@techitadmin html]# php -v
PHP 7.1.25 (cli) (built: Dec  8 2018 13:52:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

[root@techitadmin html]#

0 Comments:

Follow by Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.