How do I bulld my own version of PHP to support a new extension or feature on my server?
Posted by - NA -, Last modified by on 09 July 2009 12:45 PM
The quickest way is to use the control panel to update to the latest version of PHP with the included default extensions, but there are cases where you may need a specific version of php (older, newer, or with a specific configuration built into the php software). In cases where you can not use the version of PHP supplied on your server, nor the auto update capabilities found in your control panel - you will need to built your own version of PHP by hand (this is for advanced users familiar with unix shell and command line operation, if you are not familiar with command line operating just submit a support ticket for assistance). |
Step 1: login to your server (via SSH) and download the version of php you want from www.php.net. For example login via ssh and type:
tar xvzf php-5.2.5.tar.gz
Step 2: Configure your php (this is why you wanted to go through all this, to get a specific configuration in there!) It should look something like this:
'./configure' '--enable-cli' '--with-pear' '--prefix=/usr' '--with-exec-dir=/usr/bin' '--with-xml' '--with-curl=/usr' '--with-swf=/usr' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr' '--with-imap=/usr' '--enable-magic-quotes' '--with-mysql=/usr' '--enable-safe-mode' '--enable-track-vars' '--with-ttf' '--with-zlib' '--enable-bcmath' '--enable-calendar' '--with-freetype-dir=/usr' '--with-mcrypt' '--enable-wddx' '--with-pgsql' '--without-kerberos' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-dom' '--with-kerberos' '--with-openssl' '--with-xmlrpc' '--with-expat-dir=/usr' '--with-imap-ssl' '--with-mssql=/usr' '--with-mhash' '--enable-exif' '--enable-mbstring'
Step 3: once the configure is completed without any errors (if any errors see below) simply type
service httpd restart
This will compile, install, and restart the apache web server to use the new version of php you just built.
For further details on building your own version of php see <a href="http://www.php.net/manual/en/install.unix.php">http://www.php.net/manual/en/install.unix.php</a>
Trouble Shooting: If you run into trouble during the configure process, or make process - it's probably because you need to install development tools like the gcc compiler, and possibly some development libraries. This can vary based on which Unix (linux) version you are running, but here is a quick help for those using Centos, and Red Hat Enterprise.
First make sure you have all the development tools with this command
yum group-install "Development Tools"
This will install many packages (including the system compiler) so you can build new software, like php, manually.
For most popular php features, you may need development libraries (for instance the graphics development library called GD). You only need development libraries when you plan to build software manualy, so they are not normaly pre-installed on your server. To install them issue commands like this:
yum install gd-devel
Other popular 'devel' packages you need to install before compiling php would be the following:
yum install zlib-devel
yum install libjpeg-devel
yum install libtiff
yum install libpng-devel
yum install mysql-devel
yum install libmhash-devel
yum install libxml2-devel
yum install libmcrypt-devel
Of course if you are custom building your own php, you may need other packages than these so be sure to refer to the manual of the respective packages as needed.