How to install PHP from Source Code on CentOS 6

To install PHP from Source Code on CentOS 6  

In our previous article we have seen the installation procedure of Apache from Source Code on CentOS 6. Now, we will see the installation procedure of PHP from Source Code on CentOS 6. PHP (Hypertext Preprocessor) is a server scripting language used for the development of software applications with the help of internet. It is a powerful tool to create dynamic contents for interaction with databases. 

 

Installation procedure

To proceed with the installation procedure, execute the  below command to install required packages to compile from any source code and press y to continue with the installation. 

[root@linuxhelp ~]# yum groupinstall " Development Tools"  -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
 * base: centos.myfahim.com
 * extras: centos.myfahim.com
 * updates: centos.myfahim.com
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package patch-2.6-6.el6.x86_64 already installed and latest version
Package 1:pkgconfig-0.23-9.1.el6.x86_64 already installed and latest version
Package gettext-0.17-18.el6.x86_64 already installed and latest version
Package elfutils-0.164-2.el6.x86_64 already installed and latest version
Package cvs-1.11.23-16.el6.x86_64 already installed and latest version
Resolving Dependencies
-->  Running transaction check
--->  Package autoconf.noarch 0:2.63-5.1.el6 will be installed
--->  Package automake.noarch 0:1.11.1-4.el6 will be installed
--->  Package binutils.x86_64 0:2.20.51.0.2-5.46.el6 will be updated
.
.
.
Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6                    cpp.x86_64 0:4.4.7-18.el6                             gettext-devel.x86_64 0:0.17-18.el6                gettext-libs.x86_64 0:0.17-18.el6                   
  kernel-devel.x86_64 0:2.6.32-696.13.2.el6            libgcj.x86_64 0:4.4.7-18.el6                          libgfortran.x86_64 0:4.4.7-18.el6                 libstdc++-devel.x86_64 0:4.4.7-18.el6               
  mpfr.x86_64 0:2.4.1-6.el6                            perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6         perl-Compress-Zlib.x86_64 0:2.021-144.el6         perl-Error.noarch 1:0.17015-4.el6                   
  perl-Git.noarch 0:1.7.1-9.el6_9                      perl-HTML-Parser.x86_64 0:3.64-2.el6                  perl-HTML-Tagset.noarch 0:3.20-4.el6              perl-IO-Compress-Base.x86_64 0:2.021-144.el6        
  perl-IO-Compress-Zlib.x86_64 0:2.021-144.el6         perl-URI.noarch 0:1.40-2.el6                          perl-XML-Parser.x86_64 0:2.36-7.el6               perl-libwww-perl.noarch 0:5.833-5.el6               
  ppl.x86_64 0:0.10.2-11.el6                           systemtap-client.x86_64 0:2.9-7.el6                   systemtap-devel.x86_64 0:2.9-7.el6               

Updated:
  binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1                                                                                                                                                                        

Complete!

Now run the following command to install the dependency  package for PHP  Source Code compilation. 

[root@linuxhelp ~]# yum install libxml2-devel -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.myfahim.com
 * extras: centos.myfahim.com
 * updates: centos.myfahim.com
Resolving Dependencies
-->  Running transaction check
--->  Package libxml2-devel.x86_64 0:2.7.6-21.el6_8.1 will be installed
-->  Processing Dependency: zlib-devel for package: libxml2-devel-2.7.6-21.el6_8.1.x86_64
-->  Running transaction check
--->  Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed
-->  Finished Dependency Resolution
.
.
.
Installed:
  libxml2-devel.x86_64 0:2.7.6-21.el6_8.1                                                                                                                                                                           

Dependency Installed:
  zlib-devel.x86_64 0:1.2.3-29.el6                                                                                                                                                                                  

Complete!

Next download the source code package for PHP from its official website http://php.net/releases/.  Choose the version you want to install or else run  the below wget  command to download the source code for latest PHP  version 7.1.9. 

[root@linuxhelp ~]# wget http://in1.php.net/distributions/php-7.1.9.tar.gz
--2017-10-21 02:33:44--  http://in1.php.net/distributions/php-7.1.9.tar.gz
Resolving in1.php.net... 103.21.58.218
Connecting to in1.php.net|103.21.58.218|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19428408 (19M) [application/x-gzip]
Saving to: “ php-7.1.9.tar.gz” 

100%[==========================================================================================================================================================================> ] 19,428,408  1.11M/s   in 19s     

2017-10-21 02:34:04 (990 KB/s) - “ php-7.1.9.tar.gz”  saved [19428408/19428408]

Extract the downloaded package using tar  command. 

[root@linuxhelp ~]# tar -xzf php-7.1.9.tar.gz

Now move to extracted directory to compile PHP  source code. Run the script file called configure to continue with the configuration procedure. 

[root@linuxhelp ~]# cd php-7.1.9
[root@linuxhelp php-7.1.9]# ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
.
.
.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

Run the make command to install PHP  in its current location. 

[root@linuxhelp php-7.1.9]# make
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.9/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo 
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.9/ext/opcache/zend_accelerator_blacklist.c -o ext/opcache/zend_accelerator_blacklist.lo 
/bin/sh /root/php-7.1.9/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.9/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.9/include -I/root/php-7.1.9/main -I/root/php-7.1.9 -I/root/php-7.1.9/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.9/ext/sqlite3/libsqlite -I/root/php-7.1.9/TSRM -I/root/php-7.1.9/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.9/ext/opcache/zend_accelerator_debug.c -o ext/opcache/zend_accelerator_debug.lo
.
.
.
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP' s phar extension be enabled.
invertedregexiterator.inc
pharcommand.inc
clicommand.inc
directorytreeiterator.inc
directorygraphiterator.inc
phar.inc

Build complete.
Don' t forget to run ' make test' .

Execute the  make install command to finish the installation process by placing all PHP  files in the required  location. 

[root@linuxhelp php-7.1.9]# make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing phpdbg binary:         /usr/local/bin/
Installing phpdbg man page:       /usr/local/php/man/man1/
Installing PHP CGI binary:        /usr/local/bin/
Installing PHP CGI man page:      /usr/local/php/man/man1/
.
.
.
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/root/php-7.1.9/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers:           /usr/local/include/php/ext/pdo/

Now PHP  is successfully installed from source code. To verify the installed PHP version, run the following command. 

[root@linuxhelp php-7.1.9]# php -v
PHP 7.1.9 (cli) (built: Oct 21 2017 02:42:35) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Thus we conclude the installation procedure of PHP from the source code on CentOS 6. 

Tag : CentOS Php
FAQ
Q
What is the advantage of PHP?
A
Advantages of PHP Programming. PHP (Hypertext Pre-Processor) is a server-side web programming language that is widely used for web development. However, here are many languages which are used for web development or web programming. But among all of them PHP is the most popular web scripting language.
Q
Why PHP is better?
A
Other than that it depends on the programmer. No doubt, other languages like java,.net, python are also good to develop websites but PHP is better among them due to following factors: It is a lightweight language. It is an open source language.
Q
Share me the installation steps for php 7 on Centos?
A
For Installing PHP7 on Centos "https://www.linuxhelp.com/how-to-install-php7-on-centos7/"
Q
How can I install and make use of multiple php on single Os?
A
To install multiple PHP follow "https://www.linuxhelp.com/how-to-install-multiple-php-versions-on-centos-6/"
Q
What is its official URL for downloading the latest release of PHP?
A
To install PHP use the link as follow "ttp://php.net/releases/".