How do I compile additional PHP extensions?

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

  1. Download the appropriate version here: (if you’re using PHP 7+, you need SSH2 1.0+)

  2. 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.

  1. Right-click on the site in the site sidebar and go to “Open Site SSH”
  2. Enter apt-get update
  3. Enter apt-get install -y build-essential autoconf pkg-config to install dependencies like make, 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

  1. Enter cd /app/ssh*/ssh*
  2. Enter /opt/php/7.1.7/bin/phpize
    • Use find / -name phpize to find the location of phpize if you can’t find it
  3. Enter ./configure --with-php-config=/opt/php/7.1.7/bin/php-config
    • Use find / -name php-config to find php-config
  4. Enter make
  5. Enter make install. You should see something like Installing shared extensions: /opt/php/7.1.7/lib/php/extensions/no-debug-non-zts-20160303/
  6. Run ls -la PATHFROMABOVE to see what the new extension filename is. It’ll be something like

Configure PHP to use the extension

  1. Enter nano /conf/php/7.1.7/php.ini … Press Ctrl + W then Ctrl + V to go to the bottom of the file
  2. Add a new section that looks something like

Note: Depending on the extension, you may need to use pecl_extension= or zend_extension= instead of extension=

Restart PHP and Verify

  1. Go back to Local and right-click on the site and go to “Restart”
  2. After the site restarts, click on the i beside the PHP version to open phpinfo(). Search for SSH2 or whatever extension you installed. Chances are, if you see it, it’s working correctly :smiley:

Clean up

Remove the extension source directory in the site’s /app folder