How do I recompile PHP to upgrade or add new extensions in a VPS

In older (or custom) installations, you may need to recompile PHP to add new extensions or to upgrade to a newer version. If you need to do that, follow these steps:

  • Go to /usr/src/
  • If the source of PHP is already here go into the directory (ie. php-5.3.9), otherwise download the tarball and uncompress it in this directory
  • Grab the current configure command by executing php -i | grep configure
  • Run the configure command. If you need to add a new extension, add the new extension to the end of the configure line with the existing extensions.
  • Run make, then make install.
  • Restart apache by running service httpd restart or in the Control Panel.

Note: You could consider rebuilding your server with one of our latest images, for better support and easier management — you will be able to install PHP extensions or upgrade / downgrade PHP using you OS’s package manager.