PHP chroot() Function

Example

Change the root directory:

<?php
// Change the root directory
chroot("/path/to/chroot/");
// Get the current directory
echo getcwd();
?>

Result:

/

Definition and Usage

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

Note:This function requires root privileges and is only available on GNU and BSD systems when using CLI, CGI, or embedded SAPI. This function is not implemented on the Windows platform.

Syntax

chroot(directory);
Parameter Description
directory Required. Specifies a new root directory path.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 4.0.5+