How do I compile my own version of PHP?

This page is showing a generic answer.
To see a more detailed answer customized for you, type your domain name here:

We provide working, ready-to-go versions of PHP to all of our hosting customers.

However, we're occasionally asked if it's possible for customers to install their own, different version of PHP. People usually ask this because they need a feature from a particular PHP version. Experts can do this, as explained on this page.

Most of our customers do not need the instructions on this page. It is intended only for technically advanced customers. We don't provide any support whatsoever for this, nor for problems that result from doing it.

On this page:

Know the risks

If you use your own version of PHP, it won't work exactly like our standard version of PHP, and many of the instructions on our support website won't apply to you.

In addition, you'll probably need to recompile PHP whenever we upgrade the version of Linux on our servers (which happens about once every 18 months on average). Your custom PHP version (and thus part or all of your website) may stop working with no notice until you do so.

In short, if you do this, you're creating new problems, and you're assuming responsibility for something you don't normally have to worry about. Don't do it unless you don't care if your site stops working from time to time. It should only be used for experimental sites.

Compiling PHP

To install your own custom version of PHP, you'll need to download it, compile it, and put it in a custom location.

PHP is not an easy program to compile. To be successful, you should have experience compiling Unix software, and you should be familiar with the commands to accomplish that, including the "configure", "make" and "make install" commands.

Our servers have all the libraries necessary to compile a basic, working version of PHP. Just follow the normal PHP compilation instructions, but configure it with a prefix that installs it into a local directory you've created on your account. Something like this could work:

mkdir ~/php-private
./configure \
    -prefix=~/php-private \
    --with-config-file-path=~/php-private \
    --with-exec-dir=~/php-private/libexec \

Using the custom PHP version

When you've compiled your custom PHP version, you can force your account to use it by modifying your .htaccess file. Just set an environment variable named "USE_PHP_BINARY" containing the path to the PHP binary that you compiled and installed, together with an “AddHandler” line to ensure that FastCGI doesn’t run a different version.

For example:

SetEnv USE_PHP_BINARY /home/ex/
AddHandler application/x-httpd-php .php

If you do that, all PHP files in that directory (and its sub-directories) would be run using your "custom-php5-cgi" binary. You can also create different .htaccess files in different directories if you need to run different versions of PHP simultaneously. (Note that our servers always use PHP in CGI mode; you can't make them use PHP as a module by installing your own version.)

Keep in mind that the PHP settings page in the "My Account" control panel won't affect your custom copy of PHP, which will probably have it's own separate "php.ini" file.