The chroot() function changes the root directory of the current process to directory, and changes the current working directory to "/".
PHP chroot() Function has the following syntax.
chroot(directory);
Parameter | Is Required | Description |
---|---|---|
directory | Required. | Path to change the root directory to |
PHP chroot() Function returns TRUE on success. FALSE on failure.
This function requires root privileges, and is only available to GNU and BSD systems.
Change the root directory:
<?php
// Change root directory
chroot("/path/to/chroot/");
// Get current directory
echo getcwd();
?>
The following code shows how to change the root directory.
<?php
// Change root directory
chroot("c:/");
// Get current directory
echo getcwd();
?>