How to use Composer with Plesk PHP binaries

In Plesk 12, the Plesk developers added the ability to install a custom Plesk-built binary for different PHP versions. This way if you require PHP 5.3 or PHP 7 and your system installed version is PHP 5.4, you can selectively enable the version you want to use on a per-domain basis. And it works exceptionally well!

The only downside to having multiple PHP versions installed is that if the modules / libraries you wish to use are not available in the Plesk yum repository, you can’t use them. This is because any 3rd party libraries would need to be compiled against not only the PHP version you’re using, but specifically against the custom paths of the Plesk binary, such as /opt/plesk/php/7.0/bin

The key to solving this problem is to ensure you always use the custom path when working with 3rd party utilities. Here’s how to install a local copy of Composer:

1. Download Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

2. Install Composer using PHP 7 binary

/opt/plesk/php/7.0/bin/php composer-setup.php

If you need to use composer to install additional packages, you can do so, but make sure not to simply run “composer” or even “php composer” it must be:

/opt/plesk/php/7.0/bin/php composer.phar

Followed by the normal rest of the command.

Tip: you can run this wherever the composer.phar is, so feel free to move it around if you wish, prior to installing anything. You’ll need to avoid moving it after you’ve begun installing libraries with composer.

Jordan is a computer, security, and network systems expert and a lover of all things web and tech. Jordan consults with project management for software companies. Jordan is a founder and managing partner at Websavers Inc.

Leave a Comment