How to use Composer with Plesk PHP binaries

Websavers Inc

We now provide composer within our customized chroot environment so running simply composer should now work without having to complete the below steps, except when logged in to a VPS as root.

With Plesk 12 came the ability to install custom Plesk-built binaries for different PHP versions. This way if you require PHP 7.3 or 8.1 and your system installed version is PHP 5.4, you can selectively enable the version you want to use on a per-domain basis.

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/8.1/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

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

OR

wget --no-check-certificate -O composer-setup.php https://getcomposer.org/installer

2. Install Composer using PHP 8 binary

/opt/plesk/php/8.1/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/8.1/bin/php composer.phar

Followed by the normal remainder of the command.

Tips: 1) 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. 2) You can use whichever version of PHP that you have installed in Plesk simply by swapping out the version number in the command.

Jordan Schelew

Jordan has been working with computers, security, and network systems since the 90s and is a managing partner at Websavers Inc. As a founder of the company, he's been in the web tech space for over 15 years.
WS-Logo-only-image-large

About Websavers

Websavers provides web services like Canadian WordPress Hosting and VPS Hosting to customers all over the globe, from hometown Halifax, CA to Auckland, NZ.

If this article helped you, our web services surely will as well! We might just be the perfect fit for you.

2 Comments

  1. Paul Roberts on August 29, 2018 at 10:08 am

    I’m getting path not found for

    require ‘vendor/autoload.php’;

    do you know what the path is for php 7.0 on plesk, i installed to
    /opt/plesk/php/7.0/bin/php as above

Leave a Comment