What does it mean to 'move' a file into include path list?

痞子三分冷 提交于 2019-12-23 13:13:43

问题


In the book Zend Framework, a Beginner's guide; it says:

The contents of the library/ directory should be moved to a location in your PHP “include path” list.

I don't get it. Doesn't include path hold values that reference a certain directory in a certain location. Is that what it means? or do I litterally have to move the folder to a place that is already mentioned in "include path"?


回答1:


PHP's include_path serves the same purpose as the system's PATH environment variable:

"It defines a list of directories to search through when looking for a command to execute." (Bob Rankin, 2011).

As the previous comment by andre matos indicated, you can either copy the library directory to your system's PHP include_path directory or you can set the PHP path configuration directive, 'include_path', in your php.ini file to include the library directory as a directory for PHP to search through.

Regardless of which way you choose, you need to know your system's PHP include_path directory. To find your system's PHP include_path directory, you can either do:

% php -i | grep include_path # assuming you are on Linux

-or, create a file, e.g., 'phpinfo.php', and add the following php code:

<?php phpinfo(); ?>

and run the file through PHP,

% php phpinfo.php | grep include_path

-or, alternatively, add the file e.g., 'phpinfo.php', to a directory your web server knows about, and open it as a url in a web browser and search for 'include_path.'

For example, my system's PHP include_path is at: /usr/lib64/php

Although the easiest way is arguably to just copy the library directory to your system's PHP include_path directory (e.g., /usr/lib64/php), it is also equivalently easy to set the PHP path configuration directive 'include_path' in your system's php.ini file.

To set the PHP path configuration directive 'include_path' in your system's php.ini file, open the file and locate the 'include_path' path configuration directive under the 'Paths and Directories' section. It should look something like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Remove the ';' from the PHP 'include_path' path configuration directive for your operating system.

e.g., If you are on Linux, it should look like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Then set the PHP 'include_path' path configuration directive to the library directory, as a directory for PHP to search through.

e.g., I downloaded the ZendFramework to

/usr/src/done/ZendFramework-1.11.4-minimal/

Therefore, I must set the PHP 'include_path' configuration directive to include the library directory within the ZendFramework directory, like this:

include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"

The 'Paths and Directories' section in the system's php.ini file, should now look like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Let me explain the directories I added to the PHP 'include_path' configuration directive in the php.ini file (shown above):

The '.' is the current directory, the '/usr/lib64/php' is the system's PHP include_path directory, and the '/usr/src/done/ZendFramework-1.11.4-minimal/library' is the path to the library directory in the ZendFramework directory. Note that each directory listed in the PHP 'include_path' configuration directive must be separated by a ':' (same as the directories listed in the system's PATH environment variable).

After you have added your list of directories to the PHP 'include_path" configuration directive in the php.ini file, you must restart your web server to save the changes to PHP.

e.g., % sudo apachectl restart # assumes you are using Apache as your web server

Hope this helps,

//. Elliot




回答2:


Well... You can do both.

Add an include path to your php.ini (search for something like include_path)

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;C:\PHP\pear;C:\PHP\otherfolder"

Or move the folder to some path already included (that you will know which are after performing the previous search on php.ini).

When you do something like:

<?php include 'file.php'; ?>

If the file is not in the same directory (.) as the script you're executing php will look in the include paths defined on php.ini.



来源:https://stackoverflow.com/questions/5648358/what-does-it-mean-to-move-a-file-into-include-path-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!