# Installing and configuring PEAR packages

> Find, install and use PEAR packages in your PHP applications, and set the include path so PHP can load them.

Source: https://helpcenter.ruachost.com/developers/php/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?

- 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

Many PEAR packages are already available system‑wide on shared hosting servers.

- Log in via SSH and run:

  ```bash
  pear list
  ```
- This displays all packages currently installed for your account.

## Step 2: Install a PEAR Package

### Method 1: Using cPanel

1. Log in to **cPanel**.
2. Go to **Software → PHP PEAR Packages**.
3. Search for the package you want (e.g., `Mail`).
4. Click **Install Now**.

### Method 2: Request Support

- If you cannot install via cPanel, open a [Support ticket](https://dashboard.ruachost.com/submitticket.php?step=2&deptid=2)

  ```
  ```
- The Ruachost Support team can install the package for you.

>  Note: The `pear install` command requires superuser access and is not available on shared hosting accounts.

## Step 3: Configure the PHP Include Path

After installing a PEAR package, configure PHP to locate it.

1. Create or edit a custom `php.ini` file in your application directory.
2. Add the include path:

   ```
   include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/USERNAME/php"
   ```

   Replace `USERNAME` with your account name.
3. Save the file.

This ensures your scripts can load PEAR packages correctly.

## Step 4: Use the Package in Your Code

Example using the **Mail** package:

```
<?php
require_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

- 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.
