You can use this guide to compile most PECL extensions in Local. We’ll use SSH2 as the example here.
Download and extract the appropriate PECL extension
-
Download the appropriate version here: https://pecl.php.net/package/ssh2 (if you’re using PHP 7+, you need SSH2 1.0+)
-
Extract the archive into the site’s
/app
directory.
Install Dependencies
Required for pretty much all PHP extensions that you’ll compile. Once you do this once, you don’t need to do it for subsequent PHP extensions for this site.
- Right-click on the site in the site sidebar and go to “Open Site SSH”
- Enter
apt-get update
- Enter
apt-get install -y build-essential autoconf pkg-config
to install dependencies likemake
,gcc
compiler,autoconf
, etc.
Install Extension Dependencies
Depends on the extension you’re compiling. Sometimes there won’t be any dependencies to install prior to compiling.
Enter apt-get install -y libssh2-1-dev
to install libssh2
If you’re stuck on what extensions you need, look in the errors when running step #3 in the next section and then Google the errors or Google what dependencies XXX PHP extension needs.
Compile the extension using phpize
For info about compiling extensions with phpize
, check out http://php.net/manual/en/install.pecl.phpize.php
- Enter
cd /app/ssh*/ssh*
- Enter
/opt/php/7.1.7/bin/phpize
- Use
find / -name phpize
to find the location of phpize if you can’t find it
- Use
- Enter
./configure --with-php-config=/opt/php/7.1.7/bin/php-config
- Use
find / -name php-config
to findphp-config
- Use
- Enter
make
- Enter
make install
. You should see something likeInstalling shared extensions: /opt/php/7.1.7/lib/php/extensions/no-debug-non-zts-20160303/
- Run
ls -la PATHFROMABOVE
to see what the new extension filename is. It’ll be something likessh2.so
Configure PHP to use the extension
- Enter
nano /conf/php/7.1.7/php.ini
… Press Ctrl + W then Ctrl + V to go to the bottom of the file - Add a new section that looks something like
[ssh2]
extension=/opt/php/7.1.7/lib/php/extensions/no-debug-non-zts-20160303/ssh2.so
Note: Depending on the extension, you may need to use pecl_extension=
or zend_extension=
instead of extension=
Restart PHP and Verify
- Go back to Local and right-click on the site and go to “Restart”
- After the site restarts, click on the
i
beside the PHP version to openphpinfo()
. Search forSSH2
or whatever extension you installed. Chances are, if you see it, it’s working correctly
Clean up
Remove the extension source directory in the site’s /app
folder