How Can We Help?
< All Topics
Print

Install Additional PHP Modules Using PECL

In our panel, we provide the option to enable PHP modules that are not listed in the GUI.
For instructions on activating PHP modules that are available within the GUI, please refer documentation.

This document outlines the steps for installing PHP modules that are not mentioned in the GUI, including third-party modules.

Installing Third-Party PHP Modules Using PECL

For third-party PHP modules not listed in the GUI, clients can still install them manually using PECL (PHP Extension Community Library). PECL is a repository for PHP extensions that provide additional functionality to PHP, such as performance enhancements, database drivers, and more.
PECL is already pre-installed on your server as part of our latest update. No additional setup is required. Follow the steps below to install any PHP extension.

Steps to Install a PECL Extension

1. Access the Server via SSH

Use an SSH client (e.g., PuTTY or terminal) to log in to your server.
We are using the latest PHP version, 8.4, as an example. The PECL path varies for each PHP version, make sure to modify the command to match the version of PHP you are using.

2. Install the compiler

PECL extensions need to be compiled from the source code.

To install the necessary compiler, execute the following command on your server as the root user.

export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config

3. Install the Required Extension

Run the following command, replacing EXTENSION with the name of the PHP extension you wish to install:

/opt/cpguard/packages/php84/bin/pecl install EXTENSION

Note: Ensure to replace the PHP version with the appropriate one as needed.

Example: /opt/cpguard/packages/php84/bin/pecl install imagick

When running the installation command, you might encounter the following error:

PHP Fatal error: Uncaught Error: Call to undefined function popen() in /opt/cpguard/packages/php84/lib/php/OS/Guess.php:306

This error occurs because the popen() function is disabled in the php.ini configuration for security reasons. By default, certain PHP functions such as popen(), exec(), system(), and others are often disabled to prevent potential security vulnerabilities.

The popen() function is part of PHP’s process control functions, and it allows executing system commands. Disabling such functions is a security measure to prevent command injection or arbitrary code execution on the server.

To continue with the installation of the PHP extension, you will need to temporarily comment out the disable_functions directive in the php.ini configuration file.
You can open the php.ini file using a text editor like nano:

sudo nano /opt/cpguard/packages/php84/etc/php.ini

Search for the disable_functions directive and comment it out by adding a ; at the beginning of the line.

;disable_functions = exec,system,shell_exec,passthru,popen,proc_open,pcntl_exec,dl,eval

Once you’ve commented out the disable_functions line, save the file and continue with your PHP extension installation.
After the installation completes, immediately uncomment the disable_functions line in the php.ini file to re-enable security protections.

To view the PECL extensions installed for a specific PHP version, use the following command:

/opt/cpguard/packages/php84/bin/pecl list

4. Configure PHP to Load the Extension

After the extension is installed, configure PHP to load it by creating a new EXTENSION.ini file in the conf.d directory:

sudo bash -c "echo extension=EXTENSION.so > /opt/cpguard/packages/php84/etc/conf.d/EXTENSION.ini"

Example:

sudo bash -c “echo extension=EXTENSION.so > /opt/cpguard/packages/php84/etc/conf.d/imagick.ini”

5. Restart PHP-FPM

To apply the changes, restart PHP-FPM:

sudo service php84-fpm restart

Remove a PECL extensions

If you no longer need an extension you’ve installed, you can remove the extensions.

/opt/cpguard/packages/php84/bin/pecl uninstall EXTENSION

Example:
/opt/cpguard/packages/php84/bin/pecl uninstall imagick

The output of the above command will include the following message:

Unable to remove "extension=EXTENSION.so" from php.ini

This message can be safely ignored.

To apply the changes, restart PHP-FPM:

sudo service php84-fpm restart 
Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Table of Contents