There are two ways to install a local copy of PEAR through ftp: the old, difficult way,
and the new, easy way. The new, easy way requires an upgrade to version 1.4.x of PEAR.
Installing a local copy of PEAR through ftp has become a piece of cake in PEAR 1.4.0+.
One of the banes of many user's existence is trying to install PEAR on a remote host
that does not have shell access. Often, the only choice is to use FTP, but even this
is a problem for more complex packages that take advantage of installer features like replacements.
Here is the sequence necessary to get things running:
Make sure you have a working copy of the CLI version of PEAR on your local computer
(the "pear" command, not the web interface)
Make sure you have ftp access to the remote host, and write access through ftp
Note the full path to your home directory
Create a customized configuration file for both the local and remote host
Upload the remote configuration file to the remote host
Using the local configuration file, set the remote_config value to the location
of the configuration file on the remote host
Install packages at will!
1. Make sure you have a working copy of the CLI version of PEAR (the "pear"
command, not the web interface)
Read The installation instructions.
2. Make sure you have ftp access to the remote host, and write access through ftp
This is pretty straightforward - if you can loging using the ftp command in a DOS
prompt or from a unix shell, you have ftp access. Note that sftp is not yet supported
by PEAR, but will be as soon as the Net_FTP package supports sftp.
Write down the user and password that you need to login.
Testing write access is easy. If you can upload a file, you have write access.
3. Note the full path to your home directory
This is also pretty straightforward. Upload this script to the root directory of
your web host to find out:
Chances are, it will be something like: /home/username/htdocs.
When you log into ftp, if you can change directory to /home/username, that's great.
4. create a customized config file for both the local and the remote host
This is also quite simple. Here is how to do this on windows and unix.
Pick a location to store your local copy of the remote code. For example,
C:\remote\pear. From a Command prompt (click Start here =>
Programs and search for the Command Prompt), type:
C:\> mkdir remote
C:\> cd remote
C:\remote\> mkdir pear
C:\remote\> cd pear
C:\remote\pear> pear config-create -w C:\remote\pear remote.ini
C:\remote\pear> pear config-create /home/username/pear .pearrc
In Unix, follow a similar process:
$ mkdir remote
$ cd remote
$ mkdir pear
$ cd pear
$ pear config-create /home/mylocaluser remote.conf
$ pear config-create /home/username/pear .pearrc
5. upload the remote configuration file to the remote host
This is straightforward - in both operating systems, use ftp to upload
.pearrc to /home/username/pear/.pearrc
6. using the local configuration file, set the remote_config value to the
location of the configuration file on the remote host
C:\remote\pear\> pear -c remote.ini config-set remote_config ftp://user:firstname.lastname@example.org/.pearrc
$ pear -c remote.conf config-set remote_config ftp://user:email@example.com/.pearrc
7. install packages at will!
From this point on, you can use the pear command normally, and it will automatically
synchronize the local and the remote repositories.
How does it work?
Simple. The installer installs the package locally, and then uses Net_FTP and uploads
a copy of each locally installed file to its equivalent location remotely. All commands
that affect installation (install, upgrade, even upgrade-all) can be used with this
option. The "remote_config" option tells the installer that it should automatically
mirror the local copy to the remote host.
Even more exciting, the remote configuration file is used for any replacements. In
other words, if a file expects to get the path to data files through the data_dir
configuration directive, then it will have the path on the remote host
(/home/username/pear/data) rather than the local copy (
C:\remote\pear\data). This has
one side effect: the local copy will not work on the local machine, but if you think
of it as a backup copy (In an emergency, you can always just upload the entire contents
to the remote host using regular old ftp or scp), the reasoning becomes obvious.
It is important to note that some packages install themselves differently on windows and on
unix. Be sure you know whether this is the case before installing, or ensure that your
local and remote systems are the same kind of operating system.
In order to install a local copy of PEAR through ftp, you must have an ftp client that can set permissions
on upload. First, create a directory that is NOT in your publicly accessible web space, and name it
anything you'd like. Set it to be readable and writable by any user (permissions 0777). Then, download
a copy of http://go-pear.org/ and save it as go-pear.php. Upload go-pear.php to a subdirectory of your
publicly accessible web space. It is a very good idea to password-protect the directory containing
go-pear.php with an .htaccess file.
Next, browse to the go-pear.php file. If your web address is http://www.example.com/, you have placed
go-pear.php in public_html/install/go-pear.php, and http://www.example.com/ will browse to public_html/,
then browse to http://www.example.com/install/go-pear.php. Follow the installation prompts. When asked
where to install PEAR, choose the directory you created to be readable and writable by any user. You will
need to know the location of the cli version of PHP. To find this, browse to this script and copy the output:
echo `which php`;
// if this does not work, also try echo PHP_BIN;
After PEAR has been installed, you can use the web installer to install and upgrade packages just as you would
with any other PEAR installation. To use the files, you must set the include path in scripts on the website.
ini_set('include_path', '~/pear/lib' . PATH_SEPARATOR . ini_get('include_path'));
// From PHP 4.3.0 onwards you can use, especially useful on a shared host
set_include_path('~/pear/lib' . PATH_SEPARATOR . get_include_path());