Archived Forum Post

Index of archived forum posts


Install PHP Extension (.so) in Custom Built PHP Environment

Mar 25 '17 at 20:02


My environment:

Debian 8.7 x64 PHP7.1 packages from

I successfully installed Chilkat into system with your instructions. Also tested some modules which they are working. (


Now, Only problem is, I tested this on my server. As my real production server has custom build PHP. (I build myself with custom config).

Hence, I need tar.gz file that i can unpack to specific dir and include*.so file myself. Hope to see that on too.

Accepted Answer

Installing a PHP .so extension boils down to 2 simple things, and possibly one more. These are the three things:

  1. Copy the .so to the PHP extensions directory.
  2. Create a .ini in the PHP mods-available directory.
  3. If it exists, copy the .php file to a directory in the PHP "include_path" property/env variable

In a standard/typical PHP install, we have the following. (I'll use the actual filenames for Chilkat's PHP extension.)

(Assuming this is for PHP 7.1)

  1. Copy to /usr/lib/php/20160303
  2. Create a "chilkat.ini" file in /etc/php/7.1/mods-available (I'll explain what goes in the chilkat.ini down below..)
  3. Copy the chilkat_9_5_0.php file to the /usr/share/php directory.

What Goes in the chilkat.ini File?

The .ini file contains a single line. For any PHP extension, it's just ""

Other .ini Directories

Check to see if the following directories also exist:

  1. /etc/php/7.1/apache2/conf.d
  2. /etc/php/7.1/cli/conf.d

If so, then either copy the chilkat.ini to each of those directories, or create symbolic links in those directories (named "chilkat.ini") that point to the chilkat.ini in the mods-available directory.

The PHP Extension Directory

For PHP 7.1, the typical extension directory is /usr/lib/php/20160303. The "20160303" directory is (probably) the official release date for that version of PHP. The typical extension directories for other versions of PHP are as follows:

(PHP 5.2) /usr/lib/php/20060613
(PHP 5.3) /usr/lib/php/20090626
(PHP 5.4) /usr/lib/php/20100525
(PHP 5.5) /usr/lib/php/20121212
(PHP 5.6) /usr/lib/php/20131226
(PHP 7.0) /usr/lib/php/20151012
(PHP 7.1) /usr/lib/php/20160303

Where is my PHP Extension Directory? (and what is the "include_path", where PHP searches for .php's that are included?)

Run this PHP script to show the PHP extension directory and include_path:


$extPath = ini_get("extension_dir"); print "Extension Dir: " . $extPath . "\n";

$incPath = ini_get("include_path"); print "Include Path: " . $incPath . "\n";


For example, when I run it on a particular CentOS system where I built PHP from source and installed via "sudo make install", I get this:

Extension Dir: /usr/local/lib/php/extensions/no-debug-non-zts-20151012
Include Path: .:/usr/local/lib/php

Notice the "20151012" part of the extension dir path is a date that matches for PHP 7.0 (so we already know this must be a PHP 7.0 install).

How do I Fix an apt-get PHP Extension Install for my Custom PHP Installation?

The answer to this is simple: The typical apt-get PHP extension install will install the .so to /usr/lib/php/YYYYMMDD where the "YYYYMMDD" corresponds to the date for the particular PHP version. You just need to copy the .so from that directory to the actual PHP extension directory.

Also, check to make sure the /etc/php/PHP-VERSION/mods-available exists (where PHP-VERSION is something like "7.0"). If not, then find out where it is and copy the .ini to it. Also create the symlinks in the init.d directories if those exist.

Finally, if the PHP extension includes a .php that needs to be included within your PHP script, then you can copy it to a directory that is in the include_path. (If "." is in the include_path, then just make sure the .php file being included is located in the same directory as your PHP script.)