what does it mean “(include_path='.:/usr/share/pear:/usr/share/php')”?

后端 未结 7 2225
暗喜
暗喜 2021-02-18 16:31

I have file structure on EC2 like : but facing some file referencing problem.

index.php
-db
  -config.php
-cron
  -cron1.php

I have tried file

相关标签:
7条回答
  • 2021-02-18 16:59

    Many developers include files by pointing to a remote URL, even if the file is within the local system. For example:

    <php include("http://example.com/includes/example_include.php"); ?>
    

    With allow_url_include disabled, this method does not work. Instead, the file must be included with a local path, and there are three methods of doing this:

    By using a relative path, such as ../includes/example_include.php. By using an absolute path (also known as relative-from-root), such as /home/username/example.com/includes/example_include.php.

    By using the PHP environment variable $_SERVER['DOCUMENT_ROOT'], which returns the absolute path to the web root directory. This is by far the best (and most portable) solution. The following example shows the environment variable in action.

    Example Include

    <?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
    
    0 讨论(0)
  • 2021-02-18 16:59

    I had the same error while including file from root of my project in codeigniter.I was using this in common.php of my project.

    <?php include_once base_url().'csrf-magic-master/csrf-magic.php';  ?>
    

    i changed it to

    <?php include_once ('csrf-magic-master/csrf-magic.php');  ?>
    

    Working fine now.

    0 讨论(0)
  • 2021-02-18 17:13

    Solution to the problem

    as mentioned by Uberfuzzy [ real cause of problem ]

    If you look at the PHP constant [PATH_SEPARATOR][1], you will see it being ":" for you.

    If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts

    • . (this means the current directory your code is in)
    • /usr/share/pear
    • /usr/share/ph

    Any attempts to include()/require() things, will look in these directories, in this order.

    It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()

    That was the cause of error.

    Now coming to solution

    1. Step 1 : Find you php.ini file using command php --ini ( in my case : /etc/php5/cli/php.ini )
    2. Step 2 : find include_path in vi using esc then press /include_path then enter
    3. Step 3 : uncomment that line if commented and include your server directory, your path should look like this include_path = ".:/usr/share/php:/var/www/<directory>/"
    4. Step 4 : Restart apache sudo service apache2 restart

    This is it. Hope it helps.

    0 讨论(0)
  • 2021-02-18 17:16

    I had a similar problem. Just to help out someone with the same issue:

    My error was the user file attribute for the files in /var/www. After changing them back to the user "www-data", the problem was gone.

    0 讨论(0)
  • 2021-02-18 17:19

    Actually, the solutions is to open the php.ini file edit the include_path line and either completely change it to

    include_path='.:/usr/share/php:/usr/share/pear' 
    

    or append the

    '.:/usr/share/php:/usr/share/pear' 
    

    to the current value of include_path.

    It is further explained in : http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.phpdir

    0 讨论(0)
  • 2021-02-18 17:20

    If you look at the PHP constant PATH_SEPARATOR, you will see it being ":" for you.

    If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts.

    • . (this means the current directory your code is in)
    • /usr/share/pear
    • /usr/share/php

    Any attempts to include()/require() things, will look in these directories, in this order.

    It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()

    For your first require, if that is being included from your index.php, then you dont need the dir stuff, just do...

    require_once ( 'db/config.php');
    
    0 讨论(0)
提交回复
热议问题