25

I'm trying to build a bash script to install the Source Guardian PHP extension however the destination directory is different on every subsequent release of Ubuntu.

Installing PHP5 on Ubuntu 14.04 results in the extensions being stored in /usr/lib/php5/20121212+lfs/, in Ubuntu 15.04 this directory changes, e.g. /usr/lib/20131226/

I've checked /etc/php5/fpm/php.ini and /etc/php5/fpm/php-fpm.conf but neither of these files has any mention of 20121212+lfs or 20131226.

If I place the Source Guardian extension anywhere else, it does not load.

Is there a way to programmatically determine the extension folder?

Isometric
  • 351
  • 1
  • 3
  • 6

5 Answers5

42

Maybe you should do this:

php-config --extension-dir

If php-config doesn't exist, then apt-get install php-config if Ubuntu/Debian or yum install php-config if CentOS/Red Hat)

That command will give exact location of your php extension folder.

Don't forget to change your php.ini in order to use extensions.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
thecinefiction
  • 529
  • 4
  • 3
  • 1
    It's not simpler than parsing `php -i` output and requires an installation of extra software. Why? – cprn Apr 11 '19 at 15:21
  • php-config it's just a shell script and it comes with php if was compiled with `--with-php-config` flag. – Lucas Silva Mar 03 '21 at 13:53
33

You can use this

php -i | grep extension_dir
  • 4
    You might also want to try `php -i | grep ^extension_dir` as there is also a `sqlite3.extension_dir`. The caret will match from the beginning of the string only (for those that don't know about regex) which helps if you're using the output somehow – Sera H Jun 21 '19 at 11:59
5

You can search for the xdebug file extension: find $(php -r 'echo ini_get("extension_dir");') -type f -name 'xdebug.so'

Or just get the value: php -r 'echo ini_get("extension_dir");'

1

You can find it as well by creating a phpinfo script (a file that invokes phpinfo();) and then run it in the browser.

See the example below.

enter image description here

Julian
  • 111
  • 3
1

Just wanted to add that although

php-config --extension-dir

would give you the extension directory but usually we modify some extension location in the active php.ini file. (there can be more than one php versions installed on the system at the same time. And current php.ini file location could be found by looking to the output of phpinfo function; using finding php.ini in the output of phpinfo function).

For example, xdebug might be located in the some other folder than the extension directory using the variable zend_extension; mostly located at the end of the php.ini file.

zend_extension=/usr/lib/php/20170718/xdebug.so

So be careful when replace module file in the directory; (had made be nuts once; because although i was changing the file but was not actually reflected in the output of phpinfo file).