Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 623
Immers Avatar asked Dec 27 '22 22:12

Immers


1 Answers

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

like image 198
Elliot Avatar answered Feb 13 '23 00:02

Elliot