Monday, October 28, 2013

How to Compile PHP

How to Compile PHP

1. Prepre the environment
Install the compiler tool by issue command
apt-get install build-essential
Note: Use the same ubuntu version for the server compile and server that going to use this php.
e.g . If you want to use PHP version 5.4.13 on Ubuntu server 12.04 so we also need to compile PHP version 5.4.13 on Ubuntu
server 12.04.

2. Download PHP version that we need to compile
In this example is going to compile a PHP version 5.4.13
Create a folder to store our compile PHP version. In this example will store in "/opt/php-versions/php5413"
2.1 Create folder
mkdir -p /opt/php-versions/php5413
2.2 Download PHP version 5.4.13
wget http://tw2.php.net/distributions/php-5.4.13.tar.gz
3. Extract
tar -xvf php-5.4.13.tar.gz
4. Go to folder and run configure
Go to folder
cd php-5.4.13
Run configure
./configure --prefix=/opt/php-versions/php5413 --with-mysql=/usr
--with-mysqli=/usr/bin/mysql_config --with-curl=/usr/bin
--with-openssl-dir=/usr --with-pdo-mysql=/usr --with-xmlrpc --with-snmp=/usr
--enable-exif --enable-calendar --with-bz2=/usr --with-gd --with-jpeg-dir=/usr
--with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr
--enable-mbstring --enable-zip --with-pear --enable-cli --enable-fastcgi
--enable-discard-path --enable-force-cgi-redirect --enable-bcmath
--enable-ctype --enable-dba --enable-dom --enable-filter
--enable-ftp--enable-hash --enable-json --enable-libxml --enable-sockets
--enable-soap --with-kerberos --with-openssl --enable-memcache --enable-apc
5. Run make
make
6. Run make install
make install
7. Testing
Make sure there is no error complain on the screen, and perform test our PHP running properly with our enable modules by issue
the command and got the displayed below
root@server-name:~# /opt/php-versions/php5413/bin/php -v
PHP 5.4.13 (cli) (built: Sep 3 2013 21:52:03)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
root@server-name:~#
For an other module check we can check via phpinfo:
<?php
phpinfo();
?>

8. Additional PHP Modules

If we want to enable other module to work with this PHP 5.4.13 version that we already compile, we need to compile that module
with this PHP version:
In This example will enable module APC to work with PHP 5.4.13 that we just compile
a. Download APC
wget http://pecl.php.net/get/APC-3.0.14.tgz
b. Extract APC
tar -xzvf APC-3.0.14.tgz
c. Check PHP
Go to folder and issue command phpize
** phpize is useto prepare a PHP extension for compiling
cd APC-3.0.14
/opt/php-versions/php5413/bin/phpize
d. Configure
./configure --enable-apc --enable-apc-mmap --with-apxs
--with-php-config=/opt/php-versions/php5413/bin/php-config
e. Run make
make
f. Run make installf.
make install
g. Check the module
After issue this command the module "apc.so" should be install in if there is no error:
/opt/php-versions/php5413/lib/php/extensions/no-debug-non-zts-20100525/apc.so


Done, with Compile PHP version 5.4.13 and add Module APC
If you need other php module to work with this php version compile you can see this as sample.
Compile php modules to a PHP Version compiled.

No comments:

Post a Comment