[TUTORIAL] How to install any PHP modules using PEAR Package Manager

Hello!

This tutorial is an extension of Install/Uninstall PHP Extensions (pun not intended) for users who do not find the PHP extensions they need under Server > PHP > Install Extensions or find the module they need in the LiteSpeed repository.

PEAR package manager can also be used to to manage PECL extensions.

# change lsphp74 to any php version you have installed as default
$ cd /usr/local/lsws/lsphp74/bin
$ wget http://pear.php.net/go-pear.phar
$ ./lsphp go-pear.phar

then, using zip extension for example, run:

# install latest version of zip
$ /usr/local/lsws/lsphp74/bin/pecl install zip
# install specific version of zip
$ /usr/local/lsws/lsphp74/bin/pecl install zip-1.21.1

In your website create a php file e.g. info.php with the following contents:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

Run the file e.g. http://mywebsite.net/info.php

You should expect this result:

If you need to install any other extension find them here and here or run this command:

# change zip with any package you want to lookup
$ /usr/local/lsws/lsphp74/bin/pecl search zip

For PEAR extensions configure the extension after installation:

UBUNTU

$ sudo echo "extension=imagick.so" >> /usr/local/lsws/lsphp74/etc/php/7.4/mods-available/40-imagick.ini

ALMALINUX

$ sudo echo "extension=imagick.so" >> /usr/local/lsws/lsphp74/etc/php.d/40-imagick.ini

Restart PHP

Option 1: Go to https://SERVER_URL/managephp/installExtensions > Choose the PHP version you installed extensions for > Click on Restart PHP

Option 2: In SSH Terminal run command touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt && systemctl restart lsws

1 Like

Hello Joseph,

I am trying to install mail, mail_mime and mail_mimedecode

These are the commands i have run

cd /usr/local/lsws/lsphp74/bin

wget Source of ', htmlspecialchars($_GET['viewsource']), '

./lsphp go-pear.phar

/usr/local/lsws/lsphp74/bin/pear install mail

/usr/local/lsws/lsphp74/bin/pear install mail mail_mime

/usr/local/lsws/lsphp74/bin/pear install mail mail_mimedecode

All installed however in my php.ini they do not show installed
i have also run php -m and again they do not show installed.
running the install commands again shows they are installed already.

Hello @craig

Kindly check the tutorial I have added how to configure PEAR extensions after installation.

Thanks Joseph,

All now working :+1:
Initially i thought i still had an issue but realised my php file needed the path to php changing.
If anyone else needs it in the future the path to php is

/usr/share/php

For Manual Installation from the source code

I am getting an error. Do you know how to handle this:

/usr/local/lsws/lsphp81/bin/pecl install zip

PHP Warning: PHP Startup: Unable to load dynamic library ā€˜zip’ (tried: /usr/local/lsws/lsphp81/lib64/php/modules/zip (/usr/local/lsws/lsphp81/lib64/php/modules/zip: cannot open shared object file: No such file or directory), /usr/local/lsws/lsphp81/lib64/php/modules/zip.so (/usr/local/lsws/lsphp81/lib64/php/modules/zip.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
downloading zip-1.21.1.tgz …
Starting to download zip-1.21.1.tgz (358,030 bytes)
…done: 358,030 bytes
24 source files, building
running: phpize
Configuring for:
PHP Api Version: 20210902
Zend Module Api No: 20210902
Zend Extension Api No: 420210902
building in /usr/local/lsws/lsphp74/tmp/pear-build-rootCFCGc4/zip-1.21.1
running: /usr/local/lsws/lsphp74/tmp/zip/configure --with-php-config=/usr/local/lsws/lsphp81/bin/php-config
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for a sed that does not truncate output… /bin/sed
checking for pkg-config… /bin/pkg-config
checking pkg-config is at least version 0.9.0… yes
checking for cc… cc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether cc accepts -g… yes
checking for cc option to accept ISO C89… none needed
checking how to run the C preprocessor… cc -E
checking for icc… no
checking for suncc… no
checking for system library directory… lib
checking if compiler supports -Wl,-rpath,… yes
checking build system type… x86_64-pc-linux-gnu
checking host system type… x86_64-pc-linux-gnu
checking target system type… x86_64-pc-linux-gnu
checking for PHP prefix… /usr/local/lsws/lsphp81
checking for PHP includes… -I/usr/local/lsws/lsphp81/include/php -I/usr/local/lsws/lsphp81/include/php/main -I/usr/local/lsws/lsphp81/include/php/TSRM -I/usr/local/lsws/lsphp81/include/php/Zend -I/usr/local/lsws/lsphp81/include/php/ext -I/usr/local/lsws/lsphp81/include/php/ext/date/lib
checking for PHP extension directory… /usr/local/lsws/lsphp81/lib64/php/modules
checking for PHP installed headers prefix… /usr/local/lsws/lsphp81/include/php
checking if debug is enabled… no
checking if zts is enabled… no
checking for gawk… gawk
checking for zip archive read/writesupport… yes, shared
checking libzip… yes
checking PHP version… 8.1/8.2
checking for pkg-config… /bin/pkg-config
checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11
ERROR: `/usr/local/lsws/lsphp74/tmp/zip/configure --with-php-config=/usr/local/lsws/lsphp81/bin/php-config’ failed

What are you trying to do here? You cannot configure a module with different php version for another php version. Do you want to install for php7.4 ? Use php7.4 in all your commands etc

I want to configure zip for php8.1 with this command: /usr/local/lsws/lsphp81/bin/pecl install zip
I don’t know why it comes up with the lsphb74.

Did you do this part

I just did that, restarted and I am still getting these:

checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11
ERROR: `/usr/local/lsws/lsphp74/tmp/zip/configure --with-php-config=/usr/local/lsws/lsphp81/bin/php-config’ failed

I rebuilt the server with almalinux 8 and now everything is working as it should