Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
How to run Composer with Plesk PHP?
Answer
Run Composer from Plesk interface
In Plesk Obsidian, Composer is available as a Plesk extension. To learn more about PHP Composer Plesk extension, visit:
Run Composer from a command-line interface
To use composer with Plesk PHP (e.g. to install additional libraries), connect to a Plesk server via SSH (Linux) / RDP (Windows Server) and use the following commands, where X.X is a PHP version:
Warning: Be careful when installing untrusted packages as root/super user. See https://getcomposer.org/root for details.
-
on CentOS/RHEL-based distributions:
# /opt/plesk/php/X.X/bin/php /usr/lib64/plesk-9.0/composer.phar [options] [arguments]
-
on Debian/Ubuntu-based distributions:
# /opt/plesk/php/X.X/bin/php /usr/lib/plesk-9.0/composer.phar [options] [arguments]
-
on Windows Server:
C:\> "%plesk_dir%Additional\PleskPHPXX\php.exe" "%plesk_dir%Additional\Composer\composer.phar" [options] [arguments]
Additional Information
To add Composer to chrooted environment, visit this KB article.
Comments
27 comments
Plesk latest ver as of Mar 30th. Composer will not run under php7.2, but runs fine under 7.1 and 7.0
-bash-4.2$ /opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar update
PHP Fatal error: Uncaught Error: Class 'Phar' not found in /usr/lib64/plesk-9.0/composer.phar:23
Stack trace:
#0 {main}
thrown in /usr/lib64/plesk-9.0/composer.phar on line 23
@Robert Perrett
Am I right that you are running Plesk Onyx 17.0/17.5 on CloudLinux environment?
If so, we have an article regarding that:
Unable to install PHP dependencies via Composer when PHP by CloudLinux is used: Class 'Phar' not found in /usr/lib64/plesk-9.0/composer.phar
Where it is mentioned, that such bug is fixed in Plesk Onyx 17.8 release.
No, I am running the latest. Plesk Onyx Version 17.8.11 Update #47
@Robert
Thank you for the update.
Can you also send me your OS version? I checked this command on CentOS 7 and all is working fine.
You can check OS version using "#plesk version" command
Product version: Plesk Onyx 17.8.11
Build date: 2019/03/21 17:00
OS version: CentOS 7.6.1810
Revision: c3fb546fb867ac424d65da14d8b023f11ec0d150
Architecture: 64-bit
Wrapper version: 1.2
I also have litespeed installed which changes the php being used
@Robert Perrett
I have installed lighspeed and executed this command:
# /opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar update
with the following composer.json file:
CONFIG_TEXT: {
"require": {
"monolog/monolog": "1.0.*"
}
}
And the package has been installed as usual:
CONFIG_TEXT: Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
\- Installing monolog/monolog (1.0.2): Downloading (100%)
Writing lock file
Generating autoload files
So, I could not reproduce the issue. That is why I recommend you to contact Plesk technical support. Seems that your environment should be checked.
I also just installed centos 7 with plesk last version.
As composer is pre-installed, I need to change the used composer path to point to a plesk higher php7.2 version
For installation of drush 9 I get this
composer require drush/drush:dev-master
[InvalidArgumentException]
Package drush/drush at version 9 has a PHP requirement incompatible with your PHP version (5.4.45)
This would currently really help to use it with drupal 8 website.
Hello @Robert,
According to the documentation https://docs.drush.org/en/master/install/ you are running the command below:
-----
composer require drush/drush
-----
Looks like you run the command under system PHP
----------
# php -v
PHP 5.4.45 (cli) (built: Aug 23 2016 14:31:52)
----------
In case if it is required to run the composer command under PHP 7.2, try the command below:
--------------
/opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar require drush/drush
--------------
OK so perhaps u should also tell people that we can use aliases so we again use only composer XXX
Like
echo "alias composer='/opt/plesk/php/7.3/bin/php /usr/lib/plesk-9.0/composer.phar'" >> ~/.bashrc
source ~/.bashrc
Hello @Robert,
Thank you for the feedback!
The information in the article is the general one
Agree, an alias can be added, however, this customization is optional and calling the composer for the specific Plesk PHP version, e.g. as below:
works fine
it's very easy by this way:
ln -s /opt/plesk/php/{php_version_you_want_to_use}/bin/php /usr/local/bin/php
Then you can use:
composer install or composer update ....
Hello @kenny,
Thank you for the comment.
Indeed, this may be an alternative.
I just install a fresh machine so again my drush that was installed via composer is not working for domain users.
Composer & Drupal console work fine for domain users
Also the .promt looks different (color promt + ll not working) as under root.
Where can I apply the same .bashrc settings from root user to domain user?
Hello @Robert!
You can copy root's .bashrc (and other similar files) to domain users' home directories. For example, the following command executed as root can be used (replace "user" with the domain's user username):
cp ~/.bashrc $(cat /etc/passwd | grep user | awk -F : '{ printf $6 }')
I'm having a similar problem with my site. I have Plesk 18.x on centos server. I have a custom .bashrc in the root of my site. Composer seems to run fine, but some scripts, including the drush scripts that work with Drupal, crash at some point because they keep finding the environmental $PATH which has '/opt/plesk/php/5.6/bin' set in it. No matter how much I try to force it to look at my .bashrc pointing to '/opt/plesk/php/7.2/bin', they still find the server $PATH.
I don't even have PHP 5.6 installed anymore, and I can't seem to edit the $PATH to change it to 7.3.
Hello Thomas Potwin,
The following should work:
Or you may also try something like:
Please check the instructions on the following guide How to specify command line command "php" version for SSH user on the Plesk server?
The comments there as well provide some recommendations from other users which may be of some help.
Hi Nelson Leiva
I actually did do just that, and removed the old 5.6 PHP. I added the ne PHP 7.3 to the path, and everything works. The strange thing is the original 5.6 is still in the path, and it won't let me get rid of it. I'm not going to stress too much because things are running smoothly. If it ain't broke .....
Hello, I'm new to this.
I'm a bit confused here.
What do I have to do to install drupal commerce through composer?
Currently, I'm running on:
Plesk Onyx 17.8.11
Build date: 2019/10/24 16:00
OS version: CentOS 7.7.1908
and when I try to install with this command (composer create-project drupalcommerce/project-base mystore --stability dev)
I get this error ( [Composer\Downloader\TransportException] Peer fingerprint did not match )
Thanks in advance
Hello Spiral arts,
Try using one of the suggestions:
https://stackoverflow.com/questions/43996782/how-to-correct-the-composer-downloader-transportexception-error-for-composer
https://stackoverflow.com/questions/47527455/getting-an-error-peer-fingerprint-did-not-match-after-running-composer-update
The error is composer-specific, so in case the above wouldn't help, consider creating a topic at resources like stackoverflow.
Thanks for all the above advice, and I was finally able to make it all work.
I first uninstalled php5.6 from the server, but for some reason I can't get it to stay out of the server PATH. I added '/opt/plesk/php/7.3/bin/php' to the PATH, but it shows after the old 5.6 one. Thankfully composer and drush don't seem to care the that path is wrong because I was able to run: 'composer create-project --prefer-dist drupal/recommended-project newsite'. This made a drupal 8.8.1 site using the new layout scheme in a directory, 'newsite' off of my root. I still made a .bashrc and .profile files in my root that contain:
alias php='/opt/plesk/php/7.3/bin/php'
alias composer='/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar'
DRUSH_PHP='/opt/plesk/php/7.3/bin/php'
export PATH="$HOME/newsite/vendor/bin:$PATH"
I followed the step by step instructions at:
https://www.drupal.org/docs/8/install/add-composer-to-an-existing-site
So far I've haven't run into any problems on the site. I've been able to add new modules, and update old ones, all using composer and drush.
Hi Thomas Potwin,
I'm glad you got that working!
Thank you for sharing the steps you performed to solve that. I'm sure it will be helpful for other Plesk users.
In SSH access of ysocial.ch server while update composer in laravel It shows php low version error 7.0.33. but phpinfo function gives 7.3.19.
Philipp this is because you seems like try to run it with OS php and not the PHP version domain uses. Please make sure to run this way:
/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar update
I ran /opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar update and composer.phar is not found. This is with MediaTemple. Is there somewhere else it might be?
Hello Roc Johnson if you use Debian or Ubuntu then path a bit different:
/opt/plesk/php/7.3/bin/php /usr/lib/plesk-9.0/composer.phar update
The bad thing about Plesk is that, it doesn't run on the same PHP you choose, there are endless piles of errors. Other panels didn't face that, it's one of the things that makes me think about changing again, because apparently they won't fix it.
opt/plesk/php/7.4/bin/php /usr/lib/plesk-9.0/composer require smile/elasticsuite ~2.10.0
Could not open input file: /usr/lib/plesk-9.0/composer
Please sign in to leave a comment.