PHP Function Reference

PHP chroot() Function



The PHP chroot() function changes the root directory of the current process to directory, and changes the current working directory to "/".

This function requires root privileges, and only available to GNU and BSD systems, and only when using the CLI, CGI or Embed SAPI.

Calling this function does not change the values of the __DIR__ and __FILE__ magic constants.

Syntax

chroot(directory)

Parameters

directory Required. Specify the path to change the root directory to.

Return Value

Returns true on success or false on failure.

Example:

The example below shows the usage of chroot() function.

<?php
//changing the root directory
chroot("/path/to/chroot/");

//getting current directory
echo getcwd();
?>

The output of the above code will be:

/

❮ PHP Directory Reference