PHP Installation in Linux

0
166

PHP

Php is a server side scripting language designed for web servers.It stands for recursively php:Hypertext Preprocessor. Before we going to install PHP we have to install Apache Webserver.

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
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!

Now create a test file under apache root(/var/www/htmml/) by using vi command as follows

vi /var/www/html/test.php

Add the sample code to display php package details like version, path etc

<?php
phpinfo();
?>

Now Access the php webpage at http://ip-address/test.php. Enjoy PHP in your Linux Machine

Comments

comments