Complile and install PHP from source

Complile and install PHP from source

You can follow the steps shown below to install PHP5.2.x , PHP5.3.x and PHP5.4.x . You can download and install the desired PHP version. Please reade the Important notes before starting the installation.

Here i am using Centos 5.8 64 bit to install PHP. It will work in all the other CentOS 64 bit versions. In the 32 bit OS, there will be corresponding changes in yum install packages. You have to make sure that the installing packages are for 32 bit or not.

I have followed the steps in the following urls to setup LAMP server, i have tested and verified installation by following the steps described in there.



[root@vps ~]# cd /usr/local/src/

Download one of the following PHP packages and extract the packges as per the selected packages.

[root@vps src]# wget
[root@vps src]# wget
[root@vps src]# wget

[root@vps src]# tar -xzf php-5.2.17.tar.gz
[root@vps src]# cd php-5.2.17

Create a script, with the following contents. I have tested the following script with all the versions of PHP and it is working fine for me.



"./configure" \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/apache/conf" \
"--disable-debug" \
"--disable-rpath" \
"--enable-inline-optimization" \
"--enable-sockets" \
"--enable-wddx" \
"--enable-calendar" \
"--enable-ftp" \
"--enable-mbstring=all" \
"--enable-dom" \
"--enable-mbregex" \
"--enable-bcmath" \
"--with-openssl" \
"--with-kerberos" \
"--with-mcrypt" \
"--with-curl" \
"--with-gd" \
"--with-zlib-dir=/usr/lib" \
"--with-jpeg-dir=/usr/lib" \
"--with-png-dir=/usr/lib" \
"--with-freetype-dir=/usr/lib" \
"--with-regex=system" \
"--with-gettext" \
"--with-bz2" \
"--with-iconv" \
"--with-layout=GNU" \
"--with-imap=/usr/local/src/imap-2007f" \
"--with-imap-ssl" \
"--enable-soap" \
"--with-snmp" \
"--with-libdir=lib64" \
"--with-mysql=/usr/local/mysql" \

[root@vps php-5.2.17]# chmod +x
[root@vps php-5.2.17]# sh

[root@vps php-5.2.17]# make
[root@vps php-5.2.17]# make install

Once the installation completed, create the following link to use the php command directly in terminal.

[root@vps ~]# ln -s /usr/local/php/bin/php /usr/bin/php

Once you done the above steps, check the version of PHP using the following command

[root@vps ~]# php -v

The above compilation command will enable the following modules. You can remove unwanted php modules from the compilation step. You may encounter errors while the compilation. All the errors which i got is added in the 'Possible Error' section at the end of this article. Please check there if you encountered an error during complilation.

Modules Installed During Installation

bcmath bz2 calendar Core ctype curl date dom filter ftp gd gettext hash iconv imap json libxml mbstring mcrypt mime_magic mysql openssl pcre PDO pdo_mysql pdo_sqlite posix Reflection session SimpleXML snmp soap sockets SPL SQLite standard tokenizer wddx xml xmlreader xmlwriter zlib

Possible Errors

I got the following errors while installing php with above modules and the solution i have given fixed those errors.

Compile Time Errors:

checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

[root@vps php-5.2.17]# yum install libxml2-devel -y


configure: error: Cannot find OpenSSL's <evp.h>

[root@vps php-5.2.17]# yum install openssl-devel -y


configure: error: Please reinstall the BZip2 distribution

[root@vps php-5.2.17]# yum install bzip2-devel.x86_64 -y


checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution

[root@vps php-5.2.17]# yum install curl-devel.x86_64 -y


configure: error: libjpeg.(a|so) not found.

[root@vps php-5.2.17]# yum install libjpeg-devel.x86_64 -y


configure: error: libpng.(a|so) not found.

[root@vps php-5.2.17]# yum install libpng-devel.x86_64 -y


configure: error: freetype.h not found.

[root@vps php-5.2.17]# yum install freetype-devel.x86_64 -y


checking OpenSSL dir for SNMP... no
checking whether to enable UCD SNMP hack... no
checking for net-snmp-config... no
configure: error: snmp.h not found. Check your SNMP installation

[root@vps php-5.2.17]# yum install net-snmp-devel -y


configure: error: mcrypt.h not found. Please reinstall libmcrypt

[root@vps php-5.2.17]# yum install libmcrypt.x86_64 libmcrypt-devel.x86_64 -y


configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.


Install imap using the script described in the following url.


checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient_r under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!



Errors in Make

/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [] Error 1


Here's what you need to do to fix this issue,
1.Verify that the libtool and libtool-ltdl packages are installed.
[root@vps php-5.2.17]# yum install libtool-ltdl.x86_64 libtool.x86_64 -y

2.Symlink to

PHP looks for the libltdl library only at (for x64 at least) /usr/lib64/ The symlink to this file is not included in the libtool packages,you'll have to make it yourself
[root@vps php-5.2.17]# cd /usr/lib64
[root@vps lib64]# ln -s

Try once again...


/usr/local/imap-2007f/lib/libc-client.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [] Error 1


Install imap using the script described in the following url.


Hope the above steps helped you to install PHP....

This entry was posted in by Unknown. Bookmark the permalink.

4 thoughts on “Complile and install PHP from source”

  1. What about this error? I try to compile PHP 5.3.x with OpenSSL.

    $ ./configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-libdir=lib/x86_64-linux-gnu --prefix=/opt/php53 --with-config-file-path=/opt/php53/etc --with-config-file-scan-dir=/opt/php53/etc/php.d --disable-debug --with-pic --disable-rpath --with-bz2 --with-db4 --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --with-kerberos --enable-ucd-snmp-hack --enable-shmop --enable-calendar --without-sqlite --with-libxml-dir=/usr --enable-xml --with-mhash --with-system-tzdata --enable-force-cgi-redirect --enable-pcntl --enable-mbregex --without-readline --with-libedit --with-phar --enable-mbstring=shared --with-gd=shared --enable-bcmath=shared --enable-dba=shared --with-xmlrpc=shared --with-ldap=shared --with-ldap-sasl=/usr --with-mysql=shared,/usr --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysqli-sock=/var/run/mysqld/mysqld.sock --enable-mysqlnd=shared --with-mysqli=shared,mysqlnd --enable-dom=shared --with-pgsql=shared,/usr --enable-wddx=shared --with-snmp=shared,/usr --enable-soap=shared --with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared --with-curl=shared,/usr --enable-pdo=shared --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-mysql=shared,/usr --with-pdo-pgsql=shared,/usr --with-pdo-sqlite=shared,/usr --with-pdo-dblib=shared,/usr --with-sybase-ct=shared,/usr --enable-json=shared --enable-zip=shared --with-pspell=shared --with-tidy=shared,/usr --enable-sysvmsg=shared --enable-sysvshm=shared --enable-sysvsem=shared --enable-posix=shared --with-unixODBC=shared,/usr --with-recode=shared,/usr --with-imagick=shared,/usr --with-imap=shared,/usr --with-imap-ssl --enable-intl=shared,/usr --enable-htscanner=shared,/usr --enable-timezonedb=shared,/usr --with-ssh2=shared,/usr --with-mcrypt=shared --enable-memcache=shared --enable-memcached=shared --with-libmemcached-dir=shared,/usr --enable-opcache=shared --enable-fastcgi --with-openssl

    loading cache ./config.cache
    checking for Cygwin environment... no
    checking for mingw32 environment... no
    checking for egrep... grep -E
    checking for a sed that does not truncate output... /bin/sed
    checking host system type... x86_64-pc-linux-gnu
    checking target system type... x86_64-pc-linux-gnu
    checking for gcc... no
    checking for cc... no
    configure: error: no acceptable cc found in $PATH

  2. Typically I never remark on online journals yet your article is convincing to the point that I never stop myself to say something regarding it. You’re doing a great job Man,Keep it up. "Reservation Hotel Booking" "Online Air Ticket Booking" "Cheap Hotel Reservations Online" "Online Discount Hotel Reservations" "Discount Hotel Reservations" "Hotel Booking Services" "Discount Airline Flights" "Affordable Vacation Packages" "Affordable Honeymoon Packages"