Home » PHP

PHP chroot() function with example

PHP chroot() function: Here, we are going to learn about the PHP chroot() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 11, 2019

PHP chroot() function

The full form of chroot is "Change Root", the function chroot()" is used to change the root directory, and, also changes the current working directory to "/".




  • directory – It defines the new root directory.

Return value:

It returns a Boolean value, "TRUE" – if root directory changes successfully or "FALSE" – if root directory does not change.


chroot() will not work on Windows PHP installations. As per the reference manual, the function is only available on PHP when using in CLI/CGI/Embedded SAPI.

The chroot() function requires root privileges. Please refer to the official manual before attempting this function PHP chroot() function

We are not responsible in any way of any damage this function may cause.

The following is a sample output of the program,

    When Success:
    root directory is changed...

    When fail:
    root directory is not changed...

Example: PHP code to change the root director

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...

Reference: PHP chroot() function


Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.