English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Online Tools

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

Object Function

PHP chroot() Function Usage and Example

PHP Directory Reference Manual

The chroot() function is used to change the root directory

Syntax

bool chroot ( string $directory )

Definition and Usage

It changes the root directory of the current process to the directory passed. --PHP needs to use-enable-chroot

Note: This function can only work correctly when the system supports and runs on CLI, CGI, or embedded SAPI version. In addition, this function also requires root privileges. On my machine, only root can use it.

Parameter

NumberParameters and Description
1

directory(Required)

New root directory

Return Value

Returns TRUE on success, FALSE on failure.

Online Example

The following is the usage of this function, change the root directory:

<?php
   chroot('/server/var/www');
?>