Howto: PHP setup include_path

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:'); ?>
<? 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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • sanjay Katiyar Mar 24, 2009 @ 6:00


    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?

    • 🐧 nixCraft Mar 24, 2009 @ 11:08

      If something is commented, php will use default value.

  • finau Oct 6, 2009 @ 1:27

    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;       
    } //end function includeFile
    //example of using it  
    • tolu Oct 1, 2011 @ 11:40

      Perfect! Just solved my problem of setting my include path..

  • dummy Feb 8, 2010 @ 11:50

    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?

  • Josh Oct 8, 2011 @ 11:15

    Hi i am new to all this so please explain like i am a child,

    Basic i have a user and video folders creater in my registration and i need to access it on my client a.php & b.php on two different folder

    How do i setting include path to access the video on registration to be seen on a.php and b.php
    Many thanks

  • tim Nov 21, 2011 @ 8:48

    Simple solution…thanks for sharing.

  • Malik Perang Dec 31, 2012 @ 10:49

    how do i change the path? is it in ini_get(‘include_path’) or :../includes:’)

    please help me

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum