To install PEAR through SSH, you can use this command sequence to set up a local copy of PEAR:
$ pear -s -c ~/.pearrc -d doc_dir=~/pear/docs \ -d ext_dir=~/pear/ext -d php_dir=~/pear/lib \ -d data_dir=~/pear/data -d test_dir=~/pear/tests \ -d cache_dir=~/pear/cache -d bin_dir=~/pear/bin |
$ pear config-create /home/user/pear .pearrc |
This will create a local configuration file in a file in your home directory named .pearrc.
$ pear -c ~/.pearrc install Archive_Tar PEAR Console_Getopt XML_RPC |
$ pear install -o PEAR |
<?php ini_set('include_path', '~/pear/lib' . PATH_SEPARATOR . ini_get('include_path')); // From PHP 4.3.0 onward, you can use the following, // which especially useful on shared hosts: set_include_path('~/pear/lib' . PATH_SEPARATOR . get_include_path()); ?> |
Installing a local copy of PEAR through ftp has become a piece of cake in PEAR 1.4.3+.
Here is the sequence necessary to get things running:
Make sure you are running PHP 5.0 or newer on your local computer
Create a customized configuration file for both the local and remote host
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.
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:
<?php echo dirname(__FILE__); ?> |
Chances are, it will be something like: /home/username/htdocs or /home/username/public_html. 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.
Windows first:
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:
$ cd $ 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
If you wish to use unencrypted ftp (remember: this is inherently insecure), then use ftp:// as your stream. If you wish to use ftps, then use ftps:// as your stream. If you wish to use sftp, then use ssh2.sftp as your stream.
The path you use for the remote_config variable may need to be a full pathname, as in:
ssh2.sftp://user:pass@myremotehost.com/home/username/.pearrc |
If the initial connection attempt fails, try a relative path as in:
ftps://user:pass@myremotehost.com/.pearrc |
To set the value of the remote_config configuration variable, use this syntax:
In windows:
C:\remote\pear\> pear -c remote.ini config-set remote_config \ ftp://user:pass@myremotehost.com/.pearrc |
In Unix:
$ pear -c remote.conf config-set remote_config \ ftp://user:pass@myremotehost.com/.pearrc |
7. Manage packages at will using the remote-install, remote-uninstall, remote-upgrade and remote-upgrade-all commands.
From this point on, you can synchronize the local and the remote repositories.
How does it work?
The installer installs the package locally, and then uses ftp streams and uploads a copy of each locally installed file to its equivalent location remotely. All commands that affect installation (install, uninstall, upgrade, and upgrade-all) have corresponding remote- commands (remote-install, remote-uninstall, remote-upgrade, remote-upgrade-all). The "remote_config" option tells the installer how to retrieve the remote configuration file containing absolute paths where packages should be installed.
The remote configuration file is used for any special tasks such as 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). Note that packages installed this way will not work on the local machine, and should be thought of as a backup copy. In an emergency, you can always just upload the entire contents to the remote host using ftp or scp.
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 addition, your local packages may depend on PHP extensions. To ensure these are available on the remote server, use the output of phpinfo(); to determine which extensions are available.
<?php echo `which php`; // if this does not work, also try echo PHP_BIN; ?> |
<?php ini_set('include_path', '~/pear/lib' . PATH_SEPARATOR . ini_get('include_path')); // From PHP 4.3.0 onward, you can use the following, // which especially useful on shared hosts: set_include_path('~/pear/lib' . PATH_SEPARATOR . get_include_path()); ?> |