chroot()
chroot() — Change the root directory.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Changes the root directory of the current process to directory, and changes the current working directory to "/".
Signature
chroot(string $directory): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $directory | string | The path to change the root directory to. |
Return value
Returns true on success or false on failure.
Example
A runnable snippet:
chroot("/path/to/your/chroot/"); echo getcwd();
Output:
/
All PHP 8.5 built-in functions
Reference card built from the PHP manual page chroot() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.