How To Install a PECL Extension For LSPHP?

You may need a certain PHP PECL extension to get your application working.

There are several other ways to get a PHP PECL extension installed:

  • Check the LiteSpeed repository for package availability
  • Use lsphp5x-pear or lsphp70-pear package
  • Install the PEAR package manager
  • Compile from Source Code

Check The LiteSpeed Repository

If you installed lsphp5x or lsphp7x through the LiteSpeed CentOS repository, you can check if the PECL extension is already available in the repository.

For example, to check imagick's availability in lsphp55, you would enter the following in to the terminal:

yum search lsphp55-pecl-imagick

or

yum list lsphp55-pecl*

If the extension is there, simply yum install and your all set.

If the extension is not in our repository, you can send a request to support@litespeedtech.com requesting it's inclusion and we will evaluate the possibility of adding it.

Use "./pecl install" command

Install lsphp5x-pear or lsphp70-pear package, which will install pecl under /usr/local/lsws/lsphp5x/bin/. Then use the usual method of /usr/local/lsws/lsphp5x/bin/pecl install extention-name.

yum install lsphp56-pear
yum install ImageMagick-devel
/usr/local/lsws/lsphp56/bin/pecl install imagick

Edit related php.ini file to enable extention imagick:

vi /usr/local/lsws/lsphp56/etc/php.ini

and add the following:

extension=imagick.so

restart LSWS.

Install The PEAR Package Manager

You can also install the PEAR package manager to manage PECL extensions.

cd /usr/local/lsws/lsphp55/bin
wget http://pear.php.net/go-pear.phar
./lsphp go-pear.phar

There is a bug in PECL scripts when installed this way, which omits dynamic PHP modules including XML. You can patch it by simply editing it to remove the “-n” cauisng the problem:

vi /usr/local/lsws/lsphp55/bin/pecl
  

Remove “-n” from the following:

exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@"
  

then, using imagick for example, run

/usr/local/lsws/lsphp55/bin/pecl install imagick

imagick.so should now be installed to the correct location.

chmod a+x /usr/local/lsws/lsphp55/lib64/php/modules/imagick.so

Lastly, edit your php.ini file to enable extension

extension=imagick.so

and restart LSWS.

Compile From Source Code

You can also build the required PECL extension from source code yourself.

Let's look at an example with the PECL imagick extension on a CentOS machine. This extension is not available in the LiteSpeed repository at the time of this writing. You can perform the following steps to build it for lsphp55 yourself.

yum install epel-release
yum install gcc gcc-c++ make autoconf glibc rcs #(setup build environment)
yum install lsphp55-devel #( need devel package) 
yum install ImageMagick-devel  # need ImageMagick-devel
wget https://pecl.php.net/get/imagick-3.1.2.tgz
tar -zxvf imagick-3.1.2.tgz
cd imagick-3.1.2
/usr/local/lsws/lsphp55/bin/phpize
./configure --with-imagick=/usr/local/lsws/lsphp55 --with-php-config=/usr/local/lsws/lsphp55/bin/php-config
make
make install

The imagick extension is now installed to the following directories:

Installing shared extensions:     /usr/local/lsws/lsphp55/lib64/php/modules/
Installing header files:          /usr/local/lsws/lsphp55/include/php/

Modify the php.ini file by adding the following and restart LSWS.

extension = imagick.so

Check the phpinfo.php page and you should see imagick enabled.

You can do similar with other LSPHP versions and PECL extensions.

Let's look at another example with the PECL imagick extension on a Ubuntu/Debian machine. Assuming that you have install lsphp70 through LiteSpeed APT repository.

apt-get install libmagickwand-dev pkg-config build-essential
mkdir -p ~/tmp
pushd ~/tmp
wget https://pecl.php.net/get/imagick-3.4.3.tgz
tar -xf imagick-3.4.3.tgz
cd imagick-3.4.3
  /usr/local/lsws/lsphp70/bin/phpize
  ./configure --with-php-config=/usr/local/lsws/lsphp70/bin/php-config
  make
  make install
  echo "extension=imagick.so" >> /usr/local/lsws/lsphp70/etc/php/7.0/mods-available/40-imagick.ini
  /usr/local/lsws/bin/lswsctrl restart
 popd
 
litespeed_wiki/php/pecl-extension.txt · Last modified: 2017/05/24 14:08 by Jackson Zhang