Setting Up MongoDB driver For custom PHP build

Table of Content

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
cd mongo-php-driver

If the repository is in a .tar.gz file somewhere
curl > memcache-X.X.X.tgz
tar xvfz memcache-X.X.X.tgz
cd memcache-X-X-X/

Compile the extension from within its directory:
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626

$ ./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

$ 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:

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/’

See any operating system documentation about shared libraries for
more information, such as the ld(1) and manual pages.

Build complete.
Don’t forget to run ‘make test’.

$ make install

Open your php.ini file and add to it:

Check if module installed
$ # /web/php-5.4/bin/php -m | grep mongo

Restart your web-server or php-pool.

Leave a Reply

Your email address will not be published. Required fields are marked *