ID #98

How do I set PHP include_path?

Applies to: Grid System

There are at least 2 ways you can set your PHP include_path.

  1. Edit your PHP configuration file. Inside that file is a directive section for "Paths and Directories." You can change that value to whatever you like or add to (or eliminate) the default like this:

    include_path = .:/usr/local/lib/php:./include

    The above must be entered all on one line, with no linebreaks. The above will cause php scripts to search for a directory named "include", and will look for it under the current directory of the running script in addition to the default, which is to first search the current directory and then search the /usr/local/lib/php directory (which is a system directory that is not writeable by you and is reserved for things like PEAR).

    The format of the include_path variable is a list of directories separated with a colon. A "." (a period) in the include path means the current directory, and allows for relative includes. More information is available here.

  2. Use the function ini_set(). For example if you wanted to set your PHP include_path to ".:../:./include:../include" then you would do this in your PHP code:
    ini_set("include_path", ".:../:./include:../include");
    You can also use ini_set() to affect other PHP settings like auto_prepend_file, auto_append_file, error_reporting, etc.

Last update: 2010-09-29 16:53
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 2.9 (31 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Anonymous:
Using ini_set("include_path"... is particularly useful if you want to use something like PEAR, but your hosting provider does not have all the packages installed that you want to take advantage of. eg. My hosting provider does not include the SOAP package, so I just add the package into a directory in my web space, and then add that directory to my include path.

Added at: 2004-03-03 18:17

Comment of Anonymous:
Setting include path also helps to make keep your servers clear of duplicates if you use the same libraries for different projects on the same server. Just put the library (for example ADOdb is a popular database abstraction library) into a central folder and you can use it in multiple projects without having to worry about directory structure.
Added at: 2008-02-18 06:32

Comment of Anonymous:
Include_path errors suspected as configuration errors might be errors in php scripts run on a new installation. If scripted path errors ran on an installation that didn't report warnings then ran on an installation that does report warnings, the error might first be noticed on a new PHP installation.

I chased a posited config error that wasn't there until I realized the warnings that showed up on several pages related to code instead of configuration. Multiple errors in scripts on a new installation didn't show on the old server, and seemed to me to result from one cause until I cleaned up paths, missing files and broken function calls that all return warnings on the new installation.

Several online PHP installation error reports reference (include_path='.;C:\php5\pear'). Be sure a wrong relative path in a php script isn't the cause.
Added at: 2008-07-05 00:28

Comment of Anonymous:
To add a path to the already existing value (not just replace) do something like this:

ini_get('include_path') . PATH_SEPARATOR . '/path/to/add')

Added at: 2008-09-17 08:38

Comment of :
How can a path be added to the existing include_path in php.ini?

include_path = ${include_path}"/path/to/add"

is supposed to work, but doesn't for me. Is it because of using a linux version where values shouldn't be quoted? I've tried with and without the quotes and neither work.
Added at: 2010-04-08 12:01