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.

Restore /etc

Restore /etc

Mistake always happened, but Make sure don't make it happened again and again..!

In this Tips, We are going to solve the problem is you confuse to delete folder or everything in "etc" which is the main folder to store the configurations in Linux systems.

but this could help if you have the update to date of a "etc" backup. 

Move everything from the "etc from backup" to the "/etc "
extract the "etc from backup" and use command rsync
rsync -arl /restore/path/etc/  /etc/
Options: 
-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-r,  --recursive             recurse into directories
-l,  --links                    copy symlinks as symlinks

We use these options to support the symlink,and recursive directory in /etc
and then issue other command to reload the configurations of init.

sudo initctl reload-configuration

and waiting for a good change to reboot your server.

If  there is crash or error, You are fixed.,,,, :D

Cheers,