Installing and configuring PEAR packages
The PHP Extension and Application Repository (PEAR) provides reusable PHP libraries that simplify development. On ruachost.com, you can install and configure PEAR packages to extend your applications with features like database interaction, e‑mail handling, and XML processing.
What is PEAR?
Section titled “What is PEAR?”- A framework and distribution system for reusable PHP components.
- Includes libraries for databases, caching, authentication, and more.
- Helps developers avoid reinventing common functionality.
Step 1: Check Pre‑Installed Packages
Section titled “Step 1: Check Pre‑Installed Packages”Many PEAR packages are already available system‑wide on shared hosting servers.
-
Log in via SSH and run:
Terminal window pear list -
This displays all packages currently installed for your account.
Step 2: Install a PEAR Package
Section titled “Step 2: Install a PEAR Package”Method 1: Using cPanel
Section titled “Method 1: Using cPanel”- Log in to cPanel.
- Go to Software → PHP PEAR Packages.
- Search for the package you want (e.g.,
Mail). - Click Install Now.
Method 2: Request Support
Section titled “Method 2: Request Support”-
If you cannot install via cPanel, open a Support ticket
-
The Ruachost Support team can install the package for you.
Note: The
pear installcommand requires superuser access and is not available on shared hosting accounts.
Step 3: Configure the PHP Include Path
Section titled “Step 3: Configure the PHP Include Path”After installing a PEAR package, configure PHP to locate it.
-
Create or edit a custom
php.inifile in your application directory. -
Add the include path:
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/USERNAME/php"Replace
USERNAMEwith your account name. -
Save the file.
This ensures your scripts can load PEAR packages correctly.
Step 4: Use the Package in Your Code
Section titled “Step 4: Use the Package in Your Code”Example using the Mail package:
<?phprequire_once "Mail.php";
$headers = array( 'From' => 'sender@example.com', 'To' => 'recipient@example.com', 'Subject' => 'Test message');
$mail_object = Mail::factory('mail');$mail_object->send('recipient@example.com', $headers, 'Hello from PEAR Mail!');?>Best Practices
Section titled “Best Practices”- Always check if a package is already installed before requesting support.
- Use Composer for modern PHP projects when possible, but PEAR remains useful for legacy applications.
- Keep your include path updated if you move scripts to new directories.
- Test installations with simple scripts before deploying to production.