PHP | chroot( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The chroot() function in PHP is an inbuilt function which is used to change the root directory of the current process to directory. The chroot() function changes the current working directory to "/". The chroot() function is only available to GNU and BSD systems, and only when the user is using the CLI, CGI or Embed SAPI. Apart from this the chroot() function also requires root privileges for functioning. Syntax: chroot($directory) Parameters Used: The chroot() function in PHP accepts only one parameter as described below. $directory: It is a mandatory parameter which specifies the new path to which the root directory has to be changed. Return Value: It returns True on success and False on failure. Errors And Exceptions: The chroot() function is not available on windows platforms yet. Apart from GNU and BSD, the chroot() function is also available on SVR4 platforms. Below programs illustrate the chroot() function: Program 1: php <?php // Changing root directory chroot("/path/gfg/chroot/"); // displaying current directory echo getcwd(); ?> Output: / Program 2: php <?php // Changing root directory $flag = chroot("path/gfg/chroot/"); if($flag == true) { echo("Root Directory Has Been Successfully Changed"); } else { echo("Root Directory Cannot Be Changed"); } ?> Output: Root Directory Has Been Successfully Changed Reference : https://www.php.net/manual/en/function.chroot.php Create Quiz Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-file-handling Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like