PHP – can’t use function chroot

configurationdebianPHP

I've installed Debian 6.0.6 x86 on a VPC with the least possible software packages and when the installation completes I take a backup of the VPC and put it aside for later use.

I have installed PHP 5 via aptitude install php5 and create a PHP script file with the following content and call it test.php:

    if ( function_exists("chroot") ) {
    echo "Function works !\n";
    } else {
    echo "Function does NOT work !\n";
    }

When I run the script via command line php -f test.php it shows me Function works ! Everything fine so far.

Since the PHP version within the php5 package is pretty old I would like to compile my own version – currently 5.4.13 – so I restore my back-upped VPC image and compile it with the following parameters:

    ./configure
    --with-apxs2=/usr/bin/apxs
    --with-config-file-path=/etc/php
    --with-zlib-dir=/usr/local/zlib
    --with-bz2=/usr/local/bzip2
    --with-openssl=/usr/local/ssl
    --with-curl=/usr/local/curl
    --enable-mbstring
    --enable-intl

Output shows me:

Running system checks
checking for chroot... yes

And the compile, make and make install completes flawlessly.

When I recreate and run the test.php script now I get the message Function does NOT work !.

What is going on here I ask myself, am i running the script the wrong way since the documentation says the following: This function is only available to GNU and BSD systems, and only when using the CLI, CGI or Embed SAPI. Also, this function requires root privileges. or is there something not configured correctly ?

Update:

The reason why i try to get this chroot function to work is because i want to install Symfony2. When i run php composer.phar create-project symfony/framework-standard-edition /var/www/symfony2 from within the /root folder it throws me an error:

PHP Fatal error: require_once(): Failed opening required 'app/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/symfony2/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php on line 24

However when i install the php5 package via the apt-get manager and run the same composer command it works perfectly.
With the precompiled deb php5 package the script changes the current working directory to /var/www/symfony2 while my compiled php binary doesn't (i think).
Then i figured out my php version doesn't have any chroot function so i thought this could be the culprit.

Best Answer

Have you prepared a proper chroot for PHP to chroot into?

Simply setting an arbitrary directory is not enough - you actually need to build the chroot and ensure it includes all necessary libraries, devices and binaries.

Otherwise, basic things like DNS resolution will fail to work and you'll get random errors, hangs or app segfaults. It sounds like you are mistaking the simplicity of open_basedir with that of a chroot.

As a start, this script, once customized, should give you a basis for a chroot.

http://www.fuschlberger.net/programs/ssh-scp-sftp-chroot-jail/make_chroot_jail.sh

Dotdeb already includes pre-compiled binaries for PHP

The Dotdeb repo keeps up-to-date pre-compiled builds of the latest versions of PHP - and would be considerably easier and quicker to implement.

http://www.dotdeb.org/