On October 19, 2021, we have enabled single-sign-on for our Plesk Support Center to provide a seamless login/account experience. This implies that you’ll be able to use a single account across any of our web-facing properties.
If you had already registered your account at MyPlesk.com/Plesk360/Platform360 please use one for login. Otherwise please re-register it using the same email address as your existing Zendesk login (support account). It’s essential that you use the same email address on our support center to ensure that your tickets stay attached to the same account.

How to add Composer to a chrooted environment in Plesk?

Follow

Comments

7 comments

  • Avatar
    dWalter

    Hello Dutiko,


    I have tried with PHP 7.3 following the exact same commands but it doesn't work :(

    0
    Comment actions Permalink
  • Avatar
    Dutiko

    Hi folks.
    This is how I do with PHP 7.4 provided by Plesk :

    # ./update_chroot.sh --add /opt/plesk/php/7.4/bin/php
    # ./update_chroot.sh --add composer
    # mkdir /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/
    # mkdir -p /var/www/vhosts/chroot/usr/local/bin
    # ln -s /opt/plesk/php/7.4/bin/php /opt/plesk/php/7.4/bin/php
    # rsync -av /opt/plesk/php/7.4 /var/www/vhosts/chroot/opt/plesk/php

    and then, ./update_chroot.sh --add  for all libs in module directory :

    # for lib in /opt/plesk/php/7.4/lib/php/modules/*.so ; do ./update_chroot.sh --add ${lib} ; done

    composer and PHP need some timezone data :

    # mkdir -p /var/www/vhosts/chroot/usr/share
    # rsync -av /usr/share/zoneinfo /var/www/vhosts/chroot/usr/share/

    one final

    # ./update_chroot.sh --apply all

    and composer works

    0
    Comment actions Permalink
  • Avatar
    Fouad Ahmed Fouad

    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

    0
    Comment actions Permalink
  • Avatar
    Adam

    To add composer to a chrooted shell.

    Follow the download instructions from https://getcomposer.org/download/:

    While logged in as root

    • sudo su root
    • cd /var/www/vhosts/chroot
    • php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    • If you wish to verify composer is valid, copy the "if (hash_file('SHA384'" line from the website above
    • php composer-setup.php
    • php -r "unlink('composer-setup.php');"

    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.

    • /usr/local/psa/admin/sbin/chrootmng --remove --source=/var/www/vhosts/chroot --target=/var/www/vhosts/<domain name>
    • /usr/local/psa/admin/sbin/chrootmng --create --source=/var/www/vhosts/chroot --target=/var/www/vhosts/<domain name>

    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.

     

    0
    Comment actions Permalink
  • Avatar
    Fouad Ahmed Fouad

    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.

    0
    Comment actions Permalink
  • Avatar
    Alexandr Redikultsev

    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.

    0
    Comment actions Permalink
  • Avatar
    Alexey Lapshin

    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-

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request