Synchronizing to a Server with no Shell Access Using PEAR_RemoteInstaller
Once you have successfully installed PEAR on a development machine, how do you properly install PEAR on the live server? For many developers, this is simply a matter of repeating the same steps on the live server that are performed on the development server. However, many developers out there have the misfortune of using a shared hosting provider who does not provide a shell, but does provide PHP. In the past, this essentially eliminated any possibility of successfully installing PEAR packages.
As of PEAR 1.4.0, this is no longer an issue, thanks to the PEAR_RemoteInstaller package (http://pear.php.net/PEAR_RemoteInstaller). This package provides special commands for synchronizing a customized PEAR server and the remote server. Unlike other solutions, the only tools required to implement this are PHP 5 on your development machine, and access to an FTP server.
To get started, install PEAR_RemoteInstaller onto your development machine:
Note
Publication Limitation
Note that at the time this book was written, the latest version of PEAR_RemoteInstaller was 0.3.0, stability alpha. To install, you will need to append alpha
or -0.3.0
as in:
Or
Next, you need to create a configuration file for the remote machine using the config-create
command. However, before this is possible, it is important to know the full path to your host. The easiest system to determine this is to run this simple script on your web host:
Save this as me.php
, and upload it to your web host. When run, this will output something similar to:
Once you have this information, you can begin
This will display something similar to:
Once you have the pear.ini
file, upload it to your remote web host and save it in the /home/myuser
directory (the default directory of your FTP login). Next, we need to create our local working copy of PEAR:
If you are running Windows:
Otherwise (assuming you are running as user foo
on your development machine):
Next, determine the kind of FTP connection you use. You'll need to know your username and password for accessing FTP, and the host name. For our example, we will use myuser
and password
as the user/password combination, and yourwebsite.example.com
as the host.
If you use regular FTP, you will want to do:
If you use FTPS, you will want to do:
If you use SFTP, you will want to do:
In order to use SFTP, you need to install the SSH2 extension from pecl.php.net
(http://pecl.php.net/ssh2), an excellent extension written by Sara Golemon. On Unix, this is simple; SSH2 can be installed via:
On Windows, php_ssh2.dll
should be distributed with your distribution of PHP 5. If not, you can grab a copy from http://pecl4win.php.net.
Once we reach this stage, the next step is to try installing a package. Let's install Savant3, an excellent template engine for PHP 5+ that utilizes the elegance of PHP itself as a templating language.
If everything works, you will see:
remote install OK: savant.pearified.com/Savant3-3.0.0
At this point, fire up your FTP browser and you'll see that the files were uploaded to /home/myuser/pear/php/Savant3.php
and to the /home/myuser/pear/php/Savant3
directory.
Note
Errors about alpha/beta
If installation fails with a notice about preferred state, try appending -alpha as in:
Note
This will work because it instructs the installer to temporarily ignore your preferred_state
configuration variable and to instead download the latest alpha or more stable version. In other words, with a preferred_state of stable, if Savant3 version 3.2.0 stable is available, it will be installed. However, if version 3.2.1 alpha is available, a newer version, it will not be installed because its stability is too low. However, by appending -alpha
, the installer is instructed to instead grab the newest version 3.2.1 and install that version.
You may be thinking, how does this differ from just extracting the files and uploading them manually? The answer becomes apparent when managing more complex packages like DB_DataObject or LiveUser. Both of these packages have dependencies that must be installed in order to work. Although it is possible to manually install them and upload, it is very easy to forget a dependency. Worse, the entire process has to be repeated upon upgrade.
Installing DB_DataObject with its dependency on PEAR, Validate, and DB is as simple as:
The same is true of upgrading:
Uninstalling is also simple, and responds to the full strength of the PEAR installer's dependency validation:
Note
The rsync Method
If you are developing a complex website for a customer who has money, it may be best to develop on an identical machine with identical software and hardware configuration. Set up the entire website locally, and synchronize it with the remote website using rsync
. This still works well with using source control and a PEAR-installable package, as development should be synced with discrete package versions.