What does it mean to "move" a file to the list of included paths?

In the Zend Framework book, A Beginner's Guide; He says:

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

I do not understand. Contains no path retention values ​​that reference a specific directory in a specific location. Is that what it means? or is it inconvenient for me to move the folder to the place that was already mentioned in the "include path"?

+4
source share
2 answers

PHP include_path performs the same task as the system PATH environment variable:

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

As pointed out in a previous comment by andre matos, you can either copy the library directory to your PHP include_path directory, or you can set the PHP path configuration directive, include_path, to the php.ini file to include the library directory as a directory for searching PHP.

No matter how you choose, you need to know your PHP include_path directory. To find your PHP include_path directory, you can:

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

-or, create a file, for example, "phpinfo.php", and add the following PHP code:

 <?php phpinfo(); ?> 

and run the file through PHP,

 % php phpinfo.php | grep include_path 

-or, otherwise, add a file, for example, "phpinfo.php", to the directory that your web server knows about, and open it as a URL in a web browser and look for "include_path".

For example, my PHP include_path system is located at /usr/lib64/php

Although the easiest way is to simply copy the library directory to your PHP include_path directory (for example, / usr / lib64 / php), you can also easily set the include_path path configuration directive on your system php.ini file.

To set the PHP path configuration directive "include_path" in your php.ini system file, open the file and find the path configuration directive "include_path" in 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 configuration directive for your operating system.

For example, 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 "include_path" path configuration directive to the library directory, as the directory for PHP search.

For example, I downloaded ZendFramework on

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

Therefore, I have to set the PHP include_path configuration directive to include the library directory in the ZendFramework directory, for example:

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

The "Paths and directories" section in the php.ini system 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 added to the PHP include_path configuration directive in the php.ini file (shown above):

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

After you have added the directory listing to the PHP include_path configuration directive in the php.ini file, you must restart the 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

+9
source

Good ... You can do both.

Add the path to your php.ini (find 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 an already included path (which you will find out after performing a 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 executable php will look in the include pools defined on php.ini.

+1
source

Source: https://habr.com/ru/post/1347896/


All Articles