Suppose you have custom PHP installed in /web/php-5.4 and you want compile some PHP extension. It is very simple!
Download needed extension source. For me this is Mongo extension.
I will be download package with git clone but it does not matter. You can download tar.gz archive and unzip its.
If the repository is in git (i.e. Mongo)
cd /home/installs
git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
If the repository is in a .tar.gz file somewhere
curl http://pecl.php.net/get/memcache-X.X.X.tgz > memcache-X.X.X.tgz
tar xvfz memcache-X.X.X.tgz
cd memcache-X-X-X/
Compile the extension from within its directory:
$ /web/php-5.4/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
then
$ ./configure –with-php-config=/web/php-5.4/bin/php-config # double “-”
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 for cc… cc
….
creating libtool
appending configuration tag “CXX” to libtool
configure: creating ./config.status
config.status: creating config.h
then
$ make
/bin/bash /tmp/memcache-2.2.7/libtool –mode=compile cc -I/app/php/include/php -I. -I/tmp/memcache-2.2.7 -DPHP_ATOM_INC -I/tmp/memcache-2.2.7/include -I/tmp/memcache-2.2.7/main -I/tmp/memcache-2.2.7 -I/app/php/include/php -I/app/php/include/php/main -I/app/php/include/php/TSRM -I/app/php/include/php/Zend -I/app/php/include/php/ext -I/app/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/memcache-2.2.7/memcache.c -o memcache.lo
…
…
———————————————————————-
Libraries have been installed in:
/tmp/memcache-2.2.7/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the ù-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the ùLD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the ùLD_RUN_PATH’ environment variable
during linking
– use the ù-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to ù/etc/ld.so.conf’
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
Build complete.
Don’t forget to run ‘make test’.
then
$ make install
Open your php.ini file and add to it:
extension=mongo.so
Check if module installed
$ # /web/php-5.4/bin/php -m | grep mongo
mongo
Restart your web-server or php-pool.