Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP | exit( ) Function
Next article icon

PHP | chroot( ) Function

Last Updated : 11 Jul, 2018
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:
  1. The chroot() function is not available on windows platforms yet.
  2. 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 : http://php.net/manual/en/function.chroot.php

Next Article
PHP | exit( ) Function

S

Shubrodeep Banerjee
Improve
Article Tags :
  • Misc
  • Web Technologies
  • PHP
  • PHP-file-handling
Practice Tags :
  • Misc

Similar Reads

  • PHP chdir() Function
    PHP chdir() function is used to change the current directory to new directory path. It takes only a single argument as new directory path. Syntaxbool chdir(string $new_directory_path)ParametersThis function accepts one parameter, which is mandatory. Return ValueIt returns a boolean operator as retur
    2 min read
  • PHP | ftp_chdir() function
    The ftp_chdir() function is an inbuilt function in PHP which is used to change the current directory on the FTP server.  Syntax: ftp_chdir( $ftp_connection, $directory ) Parameter: This function accepts two parameters as mentioned above and described below:   $ftp_connection: It is required paramete
    2 min read
  • PHP | dir() Function
    The dir() function in PHP is an inbuilt function which is used to return an instance of the Directory class. The dir() function is used to read a directory, which includes the following: The given directory is opened. The two properties handle and path of dir() are available. Both handle and path pr
    2 min read
  • PHP fclose() Function
    The fclose() function in PHP is an inbuilt function that is used to close a file that is pointed by an open file pointer. The fclose() function returns true on success and false on failure. It takes the file as an argument that has to be closed and closes that file. Syntax: bool fclose( $file )Param
    2 min read
  • PHP | exit( ) Function
    The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message
    2 min read
  • PHP | ftell( ) Function
    The ftell() function in PHP is an inbuilt function which is used to return the current position in an open file. The file is sent as a parameter to the ftell() function and it returns the current file pointer position on success, or FALSE on failure.Syntax:   ftell( $file ) Parameters Used: The ftel
    2 min read
  • PHP | fstat( ) Function
    The fstat() function in PHP is an inbuilt function which is used to return information about an open file. The file name is sent as a parameter to the fstat() function and it returns an array with the following elements : Numeric Associative Description 0 dev Device number 1 ino inode number* 2 mode
    3 min read
  • PHP fputs( ) Function
    The fputs() function in PHP is an inbuilt function which is used to write to an open file. The fputs() function stops at the end of the file or when it reaches the specified length passed as a parameter, whichever comes first. The file, string, and the length that has to be written are sent as param
    3 min read
  • PHP | ftp_exec() function
    The ftp_exec() function is an inbuilt function in PHP that is used to execute a command on the FTP server. Syntax:  ftp_exec( $ftp_connection, $command ) Parameters: This function accepts two parameters as mentioned above and described below:   $ftp_connection: It is required parameter. It specifies
    2 min read
  • PHP | closedir( ) Function
    The closedir() function in PHP is an inbuilt function which is used to close a directory handle. The directory handle to be closed is sent as a parameter to the closedir() function and the closedir() closes the directory handle. The directory handle must be previously opened by the opendir() functio
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences