Applicable to:
- Plesk for Linux
Question
How to add Composer to a chrooted environment in Plesk?
Answer
Note: Such kind of setup is not possible to be done through Plesk Interface.
-
Connect to the server via SSH
-
Download the latest
update-chroot.zip
archive and unpack it:# wget https://raw.githubusercontent.com/plesk/kb-scripts/master/update-chroot/update-chroot.sh
# chmod u+x ./update-chroot.sh -
Add PHP to the chrooted template. Use the following article for detailed steps: How to add new programs to a chrooted shell environment template?
Note: If Plesk PHP is intended to be used instead of OS PHP, use solution from the following article to set it as default: How to specify PHP version for command line php for user on Plesk server
Click here to proceed with instructions for CentOS/RHEL/CloudLinux/Almalinux-
Add PHP Composer with the data files to the template:
# ./update-chroot.sh --add /usr/bin/composer
# mkdir -p /var/www/vhosts/chroot/usr/lib64/plesk-9.0/
# cp -a /usr/lib64/plesk-9.0/composer.phar /var/www/vhosts/chroot/usr/lib64/plesk-9.0/ -
Create aliases for
/opt/plesk/php/7.4/bin/php
and/usr/lib64/plesk-9.0/composer.phar
files for chroot environment:Note: Change
/opt/plesk/php/7.4/bin/php
with the required PHP version# ln -s /opt/plesk/php/7.4/bin/php /var/www/vhosts/chroot/bin/php
# ln -s /usr/lib64/plesk-9.0/composer.phar /var/www/vhosts/chroot/composer
-
Add programs required for the Composer functioning to the template:
# ./update-chroot.sh --add env
-
Apply template changes to all domains:
# ./update-chroot.sh --apply all
Click here to proceed with instructions for Debian/Ubuntu-
Add PHP Composer with the data files to the template:
# ./update-chroot.sh --add /usr/bin/composer
# mkdir -p /var/www/vhosts/chroot/usr/lib/plesk-9.0/
# cp -a /usr/lib/plesk-9.0/composer.phar /var/www/vhosts/chroot/usr/lib/plesk-9.0/ -
Create aliases for
/opt/plesk/php/7.4/bin/php
and/usr/lib/plesk-9.0/composer.phar
files for chroot environment:Note: Change
/opt/plesk/php/7.4/bin/php
with the required PHP version# ln -s /opt/plesk/php/7.4/bin/php /var/www/vhosts/chroot/bin/php
# ln -s /usr/lib/plesk-9.0/composer.phar /var/www/vhosts/chroot/composer
-
Add programs required for the Composer functioning to the template:
# ./update-chroot.sh --add env
-
Apply template changes to all domains:
# ./update-chroot.sh --apply all
-
Comments
7 comments
To add composer to a chrooted shell.
Follow the download instructions from https://getcomposer.org/download/:
While logged in as root
Now you'll may noticed that when you access the a user that is chrooted, composer is still missing.
There are a few extra commands to update the bin directories of the chrooted user/domain.
It's worth noting that if you have a bunch of chrooted users, you may want to write a script to execute the commands all in one go so it will save you a head-ache.
Good luck.
Hello, @Adam!
Thank you very much for sharing, I am sure this information will come in handy for anyone else who would like to add a composer without using update_chroot.sh.
Doen but had an error,
bash-4.4$ /opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar
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
I searched online and seems many people had the same on chroot bash on plesk, would you recommend a fix.
After doing the steps many times I still have this error
bash-4.4$ /opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar
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
Hello @Fouad Ahmed Fouad,
In case you are using CloudLinux on the server, enable the same modules as under LVE Manager > PHP Selector for the native PHP: Tools & Settings > PHP Settings > alt-php > Extensions.
In case another OS is in use - please submit ticket to us for deeper investigation: https://support.plesk.com/hc/en-us/articles/213608509-How-to-submit-a-request-to-Plesk-support-
Hi folks.
This is how I do with PHP 7.4 provided by Plesk :
and then, ./update_chroot.sh --add for all libs in module directory :
composer and PHP need some timezone data :
one final
and composer works
Hello Dutiko,
I have tried with PHP 7.3 following the exact same commands but it doesn't work :(
Please sign in to leave a comment.