krystian
04-18-2005, 11:25 PM
Hello,
I'm posting this to clear up how to find the PEAR path on probably any server, and then at the end are instructions how to use PEAR in your PHP programs.
This is intended for users of varying degrees of experiance. Some novice unix user comments are included in this writeup, so please be patient if you're an advanced user.
Tutorial:
I. Part 1: Finding PEAR directory path.
To find the PEAR directory path, take these steps. You'll actually be looking for the php path. If any step fails, go to the next step. This should be a useful reference in anticipation of any future changes which would restrict some way of returning the PEAR path (thus require an alternate way to find the PEAR path) and could permit some troubleshooting:
0. Login over SSH to your account. You will be executing (or rather: copying, pasting, and pushing enter to the following) lines which begin with a "$"
1. Use the pear command (within an SSH session):
Normally I'd use the 'pear' command as shown:
$ pear config-get php_dir
This should return:
php_dir=<THIS IS WHAT YOU ARE LOOKING FOR>
Note: Stuff in <>'s, and the <>'s themselves are not part of the real message but indicate the path you're looking for. Use these values in Part 2 of this document.
If #1 fails,
2. Use the find command (within an SSH session):
$ find / -name PEAR -print 2>/dev/null | grep --color "PEAR" -
NOTE: Be careful to do:
$ find / -name PEAR -print 2>/dev/null | grep --color "PEAR" -
NOT
$ find / -name pear -print 2>/dev/null | grep --color "PEAR" -
Why:
First one :will return the directory path to PHP:PEAR package files (YES!)
Second one :will return the directory path to the pear command (NO!)
This should return a listing of php directories (you might want to walk away and get a cup of jolt, as find is searching through the filesystem). Pick any lines output which indicate a path to a library file (PEAR is a PHP library) The text you want is everything in that line except for what appears in RED., so store the result and Goto Part 2.
If #1, #2 fail:
3. See if PEAR is even installed. If you reach this step it's probably best to submit a support ticket to your host as this may require administrator intervention:
Steps:
1. $ cd ~/public_html
2. $ echo "<?php phpinfo() ?>" > test.php
3. Point your browser to http://yourdomain.yourTLD/test.php
4. When test.php is executed you should see a page titled "PHP Version... :
Within the row titled "Configure Command", look to see if '--with-pear' appears in the column next to the "Configure Command" column. You are looking to see if instructions to enable pear are passed to the ./configure script (which would indicate support for PEAR exists with the current PHP installation)
Hint: Use the search option of your browser.
If you see '--with-pear'
Contact your host. I'm out of ideas.
If you don't see '--with-pear'
Pear isn't enabled. Contact your host to request PEAR.
I. Part 2: Using PEAR packages.
PHP needs to know where to look for PEAR packages.
Otherwise, PHP will spit errors suggesting it was looking for a file in your local directory. Suppose you are using the DB package within PEAR. DB is a database abstraction layer (http://pear.php.net/package/DB).
You will need to include the file DB.php, a file which implements the DB class that creates database connection objects, and also contains some utility routines (see: http://www.kitebird.com/articles/peardb.html).
If you don't include PEAR : DB files correctly in your php files, you'll get error messages like this:
Warning: main(DB.php): failed to open stream: No such file or directory in <currentfile> on line <currentline>
Fatal error: main(): Failed opening required 'DB.php' (include_path='<file path you specified>') in <currentfile> on line <currentline>
Solution (or if you've already seen the above and need to know what to do):
While some will argue to add:
include_path = "<path to php>" to your rc file (within the ~ directory, probably added to .bashrc if you are using bash shell), I'm going to suggest setting the path in the php files itself.
The " include_path = ... " does not work if you're porting your code to a windows server. Instead, you'll have to specify a filesystem dependant path. See: http://www.kitebird.com/articles/peardb.html#TOC_1
So, instead, I'll have the php path in my files. I'd add it to my source code php files as so:
Within somefile.php I would see it start like this (Note: replace the DB.php in the require_once function call with whatever php pear file is applicable in your case):
<?php
# path to PEAR
ini_set('include_path', "PASTE THE TEXT YOU DISCOVERED FROM PART 1 HERE");
require_once('DB.php');
Good luck out there,
Krystian.
I'm posting this to clear up how to find the PEAR path on probably any server, and then at the end are instructions how to use PEAR in your PHP programs.
This is intended for users of varying degrees of experiance. Some novice unix user comments are included in this writeup, so please be patient if you're an advanced user.
Tutorial:
I. Part 1: Finding PEAR directory path.
To find the PEAR directory path, take these steps. You'll actually be looking for the php path. If any step fails, go to the next step. This should be a useful reference in anticipation of any future changes which would restrict some way of returning the PEAR path (thus require an alternate way to find the PEAR path) and could permit some troubleshooting:
0. Login over SSH to your account. You will be executing (or rather: copying, pasting, and pushing enter to the following) lines which begin with a "$"
1. Use the pear command (within an SSH session):
Normally I'd use the 'pear' command as shown:
$ pear config-get php_dir
This should return:
php_dir=<THIS IS WHAT YOU ARE LOOKING FOR>
Note: Stuff in <>'s, and the <>'s themselves are not part of the real message but indicate the path you're looking for. Use these values in Part 2 of this document.
If #1 fails,
2. Use the find command (within an SSH session):
$ find / -name PEAR -print 2>/dev/null | grep --color "PEAR" -
NOTE: Be careful to do:
$ find / -name PEAR -print 2>/dev/null | grep --color "PEAR" -
NOT
$ find / -name pear -print 2>/dev/null | grep --color "PEAR" -
Why:
First one :will return the directory path to PHP:PEAR package files (YES!)
Second one :will return the directory path to the pear command (NO!)
This should return a listing of php directories (you might want to walk away and get a cup of jolt, as find is searching through the filesystem). Pick any lines output which indicate a path to a library file (PEAR is a PHP library) The text you want is everything in that line except for what appears in RED., so store the result and Goto Part 2.
If #1, #2 fail:
3. See if PEAR is even installed. If you reach this step it's probably best to submit a support ticket to your host as this may require administrator intervention:
Steps:
1. $ cd ~/public_html
2. $ echo "<?php phpinfo() ?>" > test.php
3. Point your browser to http://yourdomain.yourTLD/test.php
4. When test.php is executed you should see a page titled "PHP Version... :
Within the row titled "Configure Command", look to see if '--with-pear' appears in the column next to the "Configure Command" column. You are looking to see if instructions to enable pear are passed to the ./configure script (which would indicate support for PEAR exists with the current PHP installation)
Hint: Use the search option of your browser.
If you see '--with-pear'
Contact your host. I'm out of ideas.
If you don't see '--with-pear'
Pear isn't enabled. Contact your host to request PEAR.
I. Part 2: Using PEAR packages.
PHP needs to know where to look for PEAR packages.
Otherwise, PHP will spit errors suggesting it was looking for a file in your local directory. Suppose you are using the DB package within PEAR. DB is a database abstraction layer (http://pear.php.net/package/DB).
You will need to include the file DB.php, a file which implements the DB class that creates database connection objects, and also contains some utility routines (see: http://www.kitebird.com/articles/peardb.html).
If you don't include PEAR : DB files correctly in your php files, you'll get error messages like this:
Warning: main(DB.php): failed to open stream: No such file or directory in <currentfile> on line <currentline>
Fatal error: main(): Failed opening required 'DB.php' (include_path='<file path you specified>') in <currentfile> on line <currentline>
Solution (or if you've already seen the above and need to know what to do):
While some will argue to add:
include_path = "<path to php>" to your rc file (within the ~ directory, probably added to .bashrc if you are using bash shell), I'm going to suggest setting the path in the php files itself.
The " include_path = ... " does not work if you're porting your code to a windows server. Instead, you'll have to specify a filesystem dependant path. See: http://www.kitebird.com/articles/peardb.html#TOC_1
So, instead, I'll have the php path in my files. I'd add it to my source code php files as so:
Within somefile.php I would see it start like this (Note: replace the DB.php in the require_once function call with whatever php pear file is applicable in your case):
<?php
# path to PEAR
ini_set('include_path', "PASTE THE TEXT YOU DISCOVERED FROM PART 1 HERE");
require_once('DB.php');
Good luck out there,
Krystian.