[I started this post quite a while ago and forgot about it. Here it is finished. Hopefully you find something useful here]
I’ve had a few projects already where I could really use some PEAR libraries but not sufficient enough access to the server so I could install them in the system-wide PEAR include directory. I went searching for an easy to manage way to package specific PEAR libs along with apps I was building and installing for clients – something that would work without access to system-wide PHP/PEAR setup, and even in rare cases where I couldn’t write outside the document root.
First place to at least read through is the documentation. I’m going to assume you already know the basics of PEAR.
This summary will discuss the FTP method, as it seems applicable to more situations. For me – I keep my sites under version control so I need to be able to perform a local install that I can commit to the repository and either export or update on my various server environments.
* Terminal or command-line (CLI)
* CLI version of PHP
* CLI version of PEAR
Steps (code follows)
- Create a directory where you want the PEAR libs installed. Note: PEAR will create a directory named pear in the location you specify.
- CD into that directory.
- Create your config file for your local environment (probably won’t be needed on external servers unless you plan on installing from there, in which case you should create a separate config file for each site).
- Install and update packages.
- Update your app’s include paths.
- Create your config file in the PEAR directory from step 1, above. Absolute paths, absolutely!
%> pear config-create /path/to/app/htdocs/includes /path/to/app/setup/pearrc
The first path is the location where you want the files. The second path is the location where the pearrc file is located. I usually put the PEAR files in an includes directory within the site’s document root, just in case a host or client I’m dealing with doesn’t have write access in higher-level directories. It’s best to keep the pearrc file outside of the webroot, or deny access to the file via Apache’s Allow/Deny directives.
- To run PEAR commands on your local install, you will need to use the following format
%> pear -c /path/to/app/setup/pearrc [command]
(otherwise you’re likely working on system-wide changes – doesn’t help you when it’s time to deploy to the server). An example,
%> pear -c /path/to/setup/pearrc install File_CSV_DataSource
- Set your app’s includes path to search in the PEAR directory:
Change as needed.
That should do it. It’s a basic introduction, but if you already know how to use PEAR, you’re already 95% of the way there.