dannail
dannail

Reputation: 455

How to install pear, pecl extension to the php in remote linux server

I have searched through the Internet for the answer, and still don't get it.
The problem is that I can't access the remote server's OS. I can just file-transfer scripts or any files to there and run the scripts there.
So I don't know how to run any install command in the remote OS.

Can I just install the extension package by downloading the package, unzip it, then put the API files in the httpdocs folder in server, then 'include' them in my scripts for use?

In some tutorials for web, they taught that, to check if PEAR is installed in server, we can run phpinfo() in php script, then check the configure command to see if it is --with-pear or --without-pear. But I just can't see any of them in the configure command row!

they claim that beyond version 4.3 for PHP, PEAR has been installed for us. The version of mine is PHP Version 5.2.17. But I just got no method to check if it is really installed.

Upvotes: 0

Views: 3126

Answers (1)

Till
Till

Reputation: 22436

Many questions - let me try to answer each of them one by one.

Find PEAR

PEAR should be enabled by default - which would explain that you don't see this in the configure-string.

Another test is to check the value of include_path - /usr/local/pear, /usr/share/php these values (= the location of your PEAR install) depend on the OS. You can see this via phpinfo() or:

<?php
var_dump(ini_get('include_path'));
// or
var_dump(get_include_path());

To finally check if PEAR is installed, try this code:

<?php
require_once 'PEAR.php';

No error? This means that PEAR is installed and correctly configured (in your include_path).

A local PEAR tree

If PEAR is not installed or it is and you don't have write access to the location (or your administrator cannot install PEAR packages for you), the best is the following:

  • install PEAR and all required packages on your local workstation
  • copy the entire pear tree from your workstation to the server
  • adjust the include_path in your script

Adjusting the include_path

  1. Let's say on the server your directory is: /var/example.org/public
  2. Upload your entire PEAR tree (from local) into: /var/example.org/public/pear
  3. Add the following to your script:

It's important that your new 'path' comes first - prepending means that it gets searched for libraries first. So for example, if your version of PEAR is more up to date than the one already on your server, it'll use that. Less side-effects.

PHP extensions

In most cases you cannot install pecl extensions on a server without access. You could try to pre-compile the extension on in a virtual machine (with the same OS) and then upload the .so file and use dl() to load it at runtime, but this probably won't work in most situations.

Fin

I hope that makes sense.

Updated: include_path primer

Imagine this piece of code:

<?php
require 'PEAR.php';

This will make PHP search it's include_path for the location of PEAR.php.

A typical path looks like this:

.:/usr/share/php

This means the include_path contains two directories currently (: is the delimiter):

  • the current path: .
  • the path /usr/share/php

Order of these paths is crucial to PHP:

  • if PEAR.php (from our example) is found in the current directory, it's included first
  • if PEAR.php is only in /usr/share/php, PHP will still search the current directory first

The include_path is usually set in your php.ini, or at runtime (when the script is executed) using set_include_path(...) or with ini_set('include_path', ...). To get the current value of the include path you can use get_include_path() or ini_get('include_path') as well.

To avoid PHP searching the include_path, you could use the following:

<?php
require '/usr/share/php/PEAR.php'

An absolute path stops PHP from using the include_path. But since the location of PEAR is not standardized across various linux distributions, Unix, MacOSX or Windows, it's not recommended to do this.

HTH

Upvotes: 1

Related Questions