Development and databases

PHP PEAR packages in cPanel

Reviewed on 2 min read PHP PEAR

PEAR is a distribution system for PHP components and the predecessor of Composer. It is used less today, but many older applications still depend on its packages (Mail, Net_SMTP, Spreadsheet_Excel_Writer...). For new projects, use Composer.

Install a package

In cPanel, go to PHP PEAR Packages.

PHP PEAR Packages option in cPanel

From there you can search for a package by name and install it, and see the ones you already have installed so you can reinstall or remove them. If you know the exact name, you can also type it directly into the install field.

PEAR package search and installer in cPanel

Use the package in your application

Packages are installed in /home/usuario_cpanel/php (cPanel shows you the exact path on that same page). For PHP to find them, add that path to the include_path at the start of your script:

<?php
set_include_path('/home/usuario_cpanel/php' . PATH_SEPARATOR . get_include_path());

require_once 'Mail.php';

Replace usuario_cpanel with your cPanel username and Mail.php with the file of the package you use.

If you want it for the whole website without touching the code, add it to the .htaccess file in the application's folder:

php_value include_path ".:/home/usuario_cpanel/php"

If the website returns a 500 error with that line, see the .user.ini alternative in customise the PHP configuration with .htaccess.

If PHP shows Failed opening required 'Mail.php', the path is not correctly set in the include_path or the package is not installed.

You may also find useful

Something wrong or out of date? Tell us and we will review it.