“(include_path='.:/usr/share/pear:/usr/share/php')”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18119133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:00:22  来源:igfitidea点击:

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

phppathcronapache2include-path

提问by ketul shah

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

我在 EC2 上有文件结构,例如:但面临一些文件引用问题。

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

I have tried file referencing as:

我试过文件引用为:

`require_once (dirname(__FILE__).'/db/config.php');`
`require_once (($_SERVER['DOCUMENT_ROOT']).'/db/config.php');`

but cron doesn't run.it gives error in mail as

但 cron 不运行。它在邮件中给出错误

`PHP Warning:  require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

Warning: require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

PHP Fatal error:  require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3

Fatal error: require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3`

回答by Uberfuzzy

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

如果您查看 PHP 常量PATH_SEPARATOR,您会看到它是“:”。

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

如果您使用该字符拆分字符串“.:/usr/share/pear:/usr/share/php”,您将得到 3 个部分

  • . (this means the current directory your code is in)
  • /usr/share/pear
  • /usr/share/ph
  • . (这意味着您的代码所在的当前目录)
  • /usr/share/梨
  • /usr/share/ph

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

任何对 include()/require() 事物的尝试都将按此顺序在这些目录中查找。

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:

对于您的第一个要求,如果您的 index.php 中包含该要求,那么您不需要 dir 内容,只需执行以下操作:

require_once ( 'db/config.php');

回答by Abhishek Goel

Solution to the problem

问题的解决方案

as mentioned by Uberfuzzy [ real cause of problem ]

正如Uberfuzzy所提到的[问题的真正原因]

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

如果您查看 PHP 常量 [PATH_SEPARATOR][1],您会看到它是“:”。

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

如果您使用该字符拆分字符串“.:/usr/share/pear:/usr/share/php”,您将得到 3 个部分

  • . (this means the current directory your code is in)
  • /usr/share/pear
  • /usr/share/ph
  • . (这意味着您的代码所在的当前目录)
  • /usr/share/梨
  • /usr/share/ph

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

任何对 include()/require() 事物的尝试都将按此顺序在这些目录中查找。

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_pathin vi using escthen press /include_paththen 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
  1. 第1步:找到你用命令php.ini文件php --ini(在我的情况:/etc/php5/cli/php.ini
  2. 第 2 步include_path在 vi 中使用esc然后按/include_paththen查找enter
  3. 第 3 步:如果注释并包含您的服务器目录,则取消注释该行,您的路径应如下所示include_path = ".:/usr/share/php:/var/www/<directory>/"
  4. 第四步:重启apache sudo service apache2 restart

This is it. Hope it helps.

就是这个。希望能帮助到你。

回答by Gaston

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.

我的错误是 /var/www 中文件的用户文件属性。将它们改回用户“www-data”后,问题就消失了。

回答by Leemarshn

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

许多开发人员通过指向远程 URL 来包含文件,即使该文件位于本地系统中。例如:

<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:

禁用 allow_url_include 时,此方法不起作用。相反,该文件必须包含在本地路径中,有三种方法可以做到这一点:

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.

通过使用相对路径,例如../includes/example_include.php. 通过使用绝对路径(也称为relative-from-root),例如/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.

通过使用 PHP 环境变量$_SERVER['DOCUMENT_ROOT'],它返回 Web 根目录的绝对路径。这是迄今为止最好的(也是最便携的)解决方案。以下示例显示了正在运行的环境变量。

Example Include

示例包含

<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>

回答by Ivan Aranibar

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

实际上,解决方案是打开 php.ini 文件编辑 include_path 行并将其完全更改为

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

or append the

或附加

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

to the current value of include_path.

到 include_path 的当前值。

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

进一步解释如下:http: //pear.php.net/manual/en/installation.checking.php#installation.checking.cli.phpdir

回答by castis

Thats just the directories showing you where PHP was looking for your file. Make sure that cron1.phpexists where you think it does. And make sure you know where dirname(__FILE__)and $_SERVER['DOCUMENT_ROOT']are pointing where you'd expect.

这只是向您显示 PHP 正在寻找您的文件的位置的目录。确保它cron1.php存在于您认为存在的地方。并确保您知道在哪里dirname(__FILE__)$_SERVER['DOCUMENT_ROOT']指向您期望的位置。

This value can be adjusted in your php.ini file.

这个值可以在你的 php.ini 文件中调整。

回答by Bugfixer

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

我在将项目根目录中的文件包含在codeigniter.I 中时遇到了同样的错误。我在我的项目中使用了这个common.php

<?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.

现在工作正常。