THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP chroot() Function

❮ PHP Directory Reference

Example

Change the root directory:

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

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

Result:

/


Definition and Usage

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

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


Syntax

chroot(directory);

Parameter Description
directory Required. Specifies the path to change the root directory to

Technical Details

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

❮ PHP Directory Reference