Q. How do I set PHP include path?
A. The configuration file php.ini is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI version, it happens on every invocation. This file is use to setup include_path.
Method # 1- Edit php.ini file using vi text editor
Edit your /etc/php.ini file using vi text editor, type the following command at shell prompt (some Linux distro stored file at /etc/php.d/cgi/php.ini location):
# vi /etc/php.ini
Find out include_path directive and change value as per your requirements. For example following includes default path /usr/share/php and current directory. Add /apps/php directory to this path:
include_path = ".:/usr/share/php:/apps/php"
Save and close the file. Restart the web server.
# /etc/init.d/httpd restart
Method # 2 - Use ini_set function
Use ini_set to set include_path value or the given configuration option. It returns the old value on success, FALSE on failure.
For example add following to your own php script:
<? ini_set('include_path',ini_get('include_path').':../includes:'); ?>
OR
<? ini_set("include_path", ".:../:./include:../include"); ?>
Method # 2 is quite useful if your UNIX or Linux hosting provider does not provides access to php.ini file.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 08/29/06


{ 4 comments… read them below or add one }
Vivek,
In my php.ini (Fedora 8 server) file inlcude_path is commented but in the phpinfo() says
include_path “.:/usr/share/pear:/usr/share/php” .
From where it is getting these values?
If something is commented, php will use default value.
instead of using the include_path, you can use this function.
function includeFile($file_name){ $dir = array('./', 'lib/', 'db/', 'student/'); //<-- put here your website directory you want to include $level = array('', '/', '../', '../../'); //<-- you can add more deep level in this array $ini_path = array(); foreach($dir as $p){ foreach($level as $l){ $file = $l.$p.$file_name; if(file_exists($file)){ include_once($file); return; } } } } //end function includeFile //example of using it includeFile('html.php'); includeFile('libpage.php');do u know how to include a folder (consist lot php files) into another php file?
Let’s says abc/ice, ice is a folder with lot php files inside.
Here I got another abc/ice2/index.php. How to include all files in ice to index.php?