PHP chroot() function with example

PHP chroot() function: Here, we will find out about the PHP chroot() function with its syntax, parameters, returns a type, and example.

PHP chroot() function

The full type of chroot is “Change Root“, the function chroot()” is utilized to change the root registry, and, likewise changes the present working index to “/”.




  • registry – It characterizes the new root index.

Return value:

It restores a Boolean value, “Genuine” – if root registry changes effectively or “False” – if root index doesn’t change.


chroot() won’t chip away at Windows PHP establishments. According to the instructional pamphlet, the function is just accessible on PHP when utilizing in CLI/CGI/Embedded SAPI.

The chroot() function requires root benefits. If it’s not too much trouble allude to the authority manual before endeavouring this function PHP chroot() function

We are not dependable at all of any harm this function may cause.

Coming up next is an example output of the program,

    When Success:
    root directory is changed...

    When fail:
    root directory is not changed...

Example: PHP code to change the root chief

echo getcwd();

//making a directory

// Change root directory
$ret_value = chroot("/home/folder1");

if($ret_value == true)
    echo "root directory is changed...";
    echo "root directory is not changed...";

// Get current directory
echo getcwd();


root directory is changed...

Leave a Comment

error: Alert: Content is protected!!