How to add new programs to a chrooted shell environment template?

Follow

Comments

4 comments

  • Avatar
    Christian Toller

    This instruction worked fine for me. For both Plesk Onyx as well as version 12.5.

    One issue though: Executing php -v (or any other php command) resulted in errors that e.g. mysql.so could not be found.

     

    The above adds the OS version of PHP to the chroot environment, not the PHP executables that are used for the websites.

    I therefore replaced

    ./update_chroot.sh --add php

    with

    ./update_chroot.sh --add /opt/plesk/php/7.1/bin/php

    You may want to repeat that with other available php versions.

    For convenience I also linked that php binary to usr/bin:

    ln -s /opt/plesk/php/7.1/bin/php /var/www/vhosts/chroot/usr/bin/php

    Afterwards, of course, do a ./update_chroot.sh --apply <domain>|all

  • Avatar
    Alexandr Bashurov

    Hello,

    Could you please tell me if you did the step 3 with the Plesk PHP modules dir?
    To ensure that that modules and dependant libraries for them are correctly loaded, please, run the following command:
    # ./update_chroot.sh --add `/opt/plesk/php/7.1/bin/php -i | grep "^extension_dir" | awk '{ print $3"/*" }'`

    By doing that the error with mysql.so and other modules should be resolved.

    If the error persists, however, I would like you to tell me what OS do you use, so I could test and debug the script.

  • Avatar
    Christian Toller (Edited )

    Hi Alexandr,

    yes, I performed step 3. And I'm running CentOS 7.1.
    My problem description was unclear, let me add some detail.
    After following your instructions (all steps, same on Plesk Onyx and 12.5), running php inside the chrooted environment results in the following:

    bash-4.2$ php -v
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysql.so' - libmysqlclient.so.18: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - libmysqlclient.so.18: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_mysql.so' - libmysqlclient.so.18: cannot open shared object file: No such file or directory in Unknown on line 0
    No entry for terminal type "xterm";
    using dumb terminal settings.
    PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v5.0.12, Copyright (c) 2002-2015, by ionCube Ltd.

    I thought that this might be caused by the fact that I added only the OS version of PHP, not the ones provided by Plesk.
    And indeed, adding e.g. /opt/plesk/php/7.0/bin/php to the chroot environment solves the issue completely:

    bash-4.2$ opt/plesk/php/7.0/bin/php -v
    PHP 7.0.24 (cli) (built: Sep 29 2017 12:48:34) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

    I added a symbolic link from usr/bin/php to opt/plesk/php/7.0/bin/php to have that php version in the PATH.
    With that, everything works fine inside chroot.

    Now, running the command you suggested

    # ./update_chroot.sh --add `/opt/plesk/php/7.0/bin/php -i | grep "^extension_dir" | awk '{ print $3"/*" }'`

    doesn't seem to change anything. After executing it and applying the new chroot template, I still get the same warnings as above if I call the OS version (5.6) of php and everything works just fine for the Plesk php version (7.0).

    The point is, because I want to use the same PHP version for delivering the website via http and when running some tests via PHP CLI within the chrooted shell, I'm not interested in getting the OS PHP version to work. As long as all the PHP versions from /opt/plesk/php are working, I'm happy.

    Does that make sense? ;)

    Christian Toller
    tethis IT
    Vienna, Austria

  • Avatar
    Alexandr Bashurov

    Hello,

    Well then, the root cause of the issue is quite clear:
    CentOS 7 has a pretty different idea of which libraries should reside where. As a result, all mysql-related PHP modules which have a dependancy on /usr/lib64/mysql/libmysqlclient.so.18 cannot find it.

    The library libmysqlclient.so.18 is placed in /usr/lib64/mysql/, which is a non-standard location for a shared library, so locations for shared libraries on CentOS 7 are appended with /usr/lib64/mysql/.

    update_chroot script, however, does not copy /etc/ld.so.conf and contents of /etc/ld.so.conf.d/ to the template, and as a result, OS-provided PHP cannot find the shared library throwing a bunch of warnings.

    As a result, resolving this issue is quite simple:

    1. Add required folders and files to the template:
      # cp -a /etc/ld.so.conf* /var/www/vhosts/chroot/etc
    2. Add ldconfig to the template to rebuild paths:
      # ./update_chroot.sh --add ldconfig
    3. Log in to the chroot template:
      # chroot /var/www/vhosts/chroot
    4. Update the libraries paths':
      # ldconfig -v

    After that OS-provided PHP should not return any warnings:
    # php -v
    No entry for terminal type "screen-256color";
    using dumb terminal settings.
    PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v5.0.18, Copyright (c) 2002-2015, by ionCube Ltd.

    Right now I am modifying the script to take ld.so.conf into account and update the environment after program installation, so new libraries' locations are automatically loaded.

Please sign in to leave a comment.

Have more questions? Submit a request