Install pear without network (no internet access/offline)

I was faced with a problem. I wanted to use drush on a server that had no internet access. Well, I could connect to it but it could not (for security reasons) connect to the outside world.

Drush requires PEAR's Console_Table and that in turns requires PEAR, obviously.

First I downloaded all the PEAR packages that I needed from my desktop and then I uploaded them to the server using SFTP. I could also have used a USB key if I had physical access to the server but that as not my case.

The files that I downloaded were the .tgz files that I found here:

http://pear.php.net/package/PEAR/download

That was for the PEAR package but you will also need:

http://pear.php.net/package/Console_Getopt/download
http://pear.php.net/package/Archive_Tar/download
http://pear.php.net/package/Structures_Graph/download

Since I needed Console_Table, I also downloaded it.
http://pear.php.net/package/Console_Table/download

For each one of those, click on the version number right below "Download (for manual installation only)".

So here is what I did to get it working:

# Create temporary folder that I will get ride of later.
mkdir pear-temp
cd pear-temp

# Then I uploaded all the PEAR packages to that temp folder using SFTP.
# If you use a USB key, then you copy them all like this:
cp /mnt/usb/*.tgz ./

# We will extract the core packages in a separate folder.
mkdir lib
tar x -C lib -zf PEAR-*.tgz
tar x -C lib -zf Console_Getopt-*.tgz
tar x -C lib -zf Archive_Tar-*.tgz
tar x -C lib -zf Structures_Graph-*.tgz

# This bash function is to be able to set the include_path joined by colons.
function join() {
    local IFS=$1
    shift
    echo "$*"
}

# pear requires output buffering and needs to load all the core packages from the lib folder.
PHPOPT="-d output_buffering=1 -d include_path=.:$(join ':' lib/*)"

# First we setup our configuration file.
php $PHPOPT lib/PEAR-*/scripts/pearcmd.php config-create $HOME/ $HOME/.pearrc

# Now we install ALL our packages.  Make sure you have all the required dependencies as well.
php $PHPOPT lib/PEAR-*/scripts/pearcmd.php install -o -O *.tgz

# Cleanup
cd ..
rm -Rf pear-temp

# Put pear in your path:
PATH="$PATH:$HOME/pear"

# Edit your .profile or .bashrc if you want this to be permanent.

# Edit your php.ini too or add it using set_include_path() function, whichever :)

# Drink to sucess!

Simple, huh? ;)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You may post PHP code. You should include <?php ?> tags.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options