Linux where are php extensions

Where is «./» in php.ini extensions directory pointing to?

I haven’t found any definition of what the current directory is while parsing a php.ini file, this post suggests that it is relative to the php.ini files location.

Thanks Anders, I kind of thought that, but I don’t know if it’s php.ini’s current directory, or if it’s something else’s current directory, perhaps php engine file (i don’t know if that’s the term) or (most likely not) apache’s. :S

That was a far more difficult question, I’ve updated my answer with a source but I haven’t been able to verify it.

Hey Anders, I don’t know if this is a good practice or not, but since changing the «ext = /.» line to something else was breaking the other extensions (which I couldn’t find anywhere). I ended up using the directory structure on the extension=/my/directory/structure/extension.so and it worked. Thanks for your help! 🙂

Just adding in for future searches

Running phpinfo on the cli (php -aphpinfo();) gave me this among the output.

extension_dir => /usr/lib/php/20131226 => /usr/lib/php/20131226 

Finding the directory is one thing, but understanding why it uses that one is still a bit mysterious to me (the value in php.ini is commented out by default). Mine happens to be in /etc/lib64/php/modules/ , which is obviously a feature of the 64-bit architecture.

It appears that «current directory» is, as far as PHP is concerned, whatever directory «pwd» prints.

The easiest way to see this is to run php -r ‘echo getcwd();’

I can also determine this is by typing zend_extension=»xdebug.so» inside my php.ini . Next, I create two folders anywhere: One empty, and the other I copy my xdebug.so into. When I open a terminal inside my empty folder and run php , it generates a warning about not being able to find xdebug.so. In contrast, if I open the terminal in the folder with the extension and run php at the prompt, there are no warnings.

I couldn’t determine where this maps to when running php through apache. I tried the document root, HTTPD_ROOT, /usr/bin. Nothing. I’m making this note incase someone who knows more about apache can shed some light on this.

As far as, extension_dir’s default location. That is compiled in. You can find the value for your extension_dir by finding the file build-defs.h. It’s defined in the macro PHP_EXTENSION_DIR build-defs.h is created by a template file during the configure stage of compilation.

Источник

how to know which php extensions are installed

I need to install on a lamp server exactly the same php extensions that are installed on an old server, how do to know exactly which extensions are installed in order to install the same on the new server?

3 Answers 3

You can use the command line switch -m to php to see what modules are installed.

$ php -m | head [PHP Modules] bz2 calendar ctype curl date dbase dom exif fileinfo . 

You could also use php -i to get phpinfo(); output via the command line which would include this info as well.

Читайте также:  Dell latitude 120l linux

References

If the extension is actually being used, it will need to be referenced in php.ini somewhere. Extensions are loaded in a pretty intuitive manner:

extension=msql.so extension=/path/to/extension/msql.so 

One thing to watch out for are extensions that are brought in by an additional ini file being included. I’m not sure about Debian, but on RHEL there’s a /etc/php.d/ directory where all .ini files are treated like as if they had been in the main /etc/php.ini

If it’s not in one of those two places (main php.ini or one of the included files) then the extension is more or less just sitting on the filesystem not being used.

Actually, I think I lied. You may have to look at your php files for calls to dl(). I don’t know of many people who load extensions like that, though. Not even sure what the use case would be but it’s another area you should probably check.

It’s been a while since I built PHP, but I think you can also choose to have extensions compiled in statically, at which point neither of these options will help.

In Debian, PHP extensions are loaded via files in /etc/php5/conf.d

There are two types of PHP Debian packages that might be installed here:

  • Debian PHP packages (which have names starting with php5- )
  • PECL PHP packages (which have names starting with php- )

To list both on your system, you can use this command: dpkg -l | grep ‘ii php5\?-‘ which lists installed packages starting with either php- or php5- .

You also might have extensions that were built with PECL from source code. List those with: pecl list

Finally, it’s possible to compile your own extensions the old fashioned way. In that case they might not have a file in /etc/php5/conf.d but might be added to php.ini itself.

All extensions usually have a section of output from phpinfo();. php -m will show the list of what extensions PHP has loaded (each of which should have a spot in the phpinfo output). There will be many more extensions listed in the php -m output than are installed as add-on packages in Debian, because there are lots of default extensions built into PHP as well as the ones you can install afterwards.

Here is example output from a development machine listing extra installed PHP extensions:

root@zaphod:~# dpkg -l | grep 'ii php5\?-' ii php-auth-sasl 1.0.4-1 all Abstraction of various SASL mechanism responses ii php-db 1.7.14-2 all PHP PEAR Database Abstraction Layer ii php-mail 1.2.0-4 all PHP PEAR module for sending email ii php-mail-mime 1.8.4-1 all PHP PEAR module for creating MIME messages ii php-mail-mimedecode 1.5.5-1 all PHP PEAR module to decode MIME messages ii php-net-smtp 1.6.1-1 all PHP PEAR module implementing SMTP protocol ii php-net-socket 1.0.9-2 all PHP PEAR Network Socket Interface module ii php-pear 5.4.39-0+deb7u2 all PEAR - PHP Extension and Application Repository ii php-xml-parser 1.3.4-6 all PHP PEAR module for parsing XML ii php5-cgi 5.4.39-0+deb7u2 amd64 server-side, HTML-embedded scripting language (CGI binary) ii php5-cli 5.4.39-0+deb7u2 amd64 command-line interpreter for the php5 scripting language ii php5-common 5.4.39-0+deb7u2 amd64 Common files for packages built from the php5 source ii php5-curl 5.4.39-0+deb7u2 amd64 CURL module for php5 ii php5-dev 5.4.39-0+deb7u2 amd64 Files for PHP5 module development ii php5-gd 5.4.39-0+deb7u2 amd64 GD module for php5 ii php5-imagick 3.1.0~rc1-1+b2 amd64 ImageMagick module for php5 ii php5-imap 5.4.39-0+deb7u2 amd64 IMAP module for php5 ii php5-intl 5.4.39-0+deb7u2 amd64 internationalisation module for php5 ii php5-mcrypt 5.4.39-0+deb7u2 amd64 MCrypt module for php5 ii php5-mysql 5.4.39-0+deb7u2 amd64 MySQL module for php5 ii php5-pgsql 5.4.39-0+deb7u2 amd64 PostgreSQL module for php5 ii php5-sqlite 5.4.39-0+deb7u2 amd64 SQLite module for php5 ii php5-suhosin-extension 0.9.37-2 amd64 advanced protection system for PHP5 ii php5-sybase 5.4.39-0+deb7u2 amd64 Sybase / MS SQL Server module for php5 ii php5-xdebug 2.2.1-2 amd64 Xdebug Module for PHP 5 root@zaphod:~# pecl list Installed packages, channel pecl.php.net: ========================================= Package Version State APC 3.1.13 beta memcache 3.0.8 beta 

Источник

Читайте также:  Python make linux executable

Locating PHP extension folder using bash

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?

5 Answers 5

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.

php-config it’s just a shell script and it comes with php if was compiled with —with-php-config flag.

php -i | grep extension_dir 

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

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»);’

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

enter image description here

Just wanted to add that although

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

Источник

How do I see the extensions loaded by PHP?

It’s got to be somewhere in the phpinfo() dump, but I just don’t know where. Is it supposed to be under the «Additional Modules» section? Somewhere else? I’m trying to figure out why some extensions don’t appear to be loaded, but I don’t even know where I should be looking.

Читайте также:  Linux установка драйверов из архива

11 Answers 11

This will you give you the modules loaded in PHP CLI context, which might be a different PHP than the one that is serving web requests

Run command. You will get installed extentions:

php -r "print_r(get_loaded_extensions());" 

Or run this command to get all module install and uninstall with version

Or if you need it to look prettier (e.g. comma separated): php -r «print_r(implode(‘, ‘, get_loaded_extensions()));»

This works on the command line php -r ‘print_r(get_loaded_extensions());’ it outputs the same list as php -m

cmd to export modules with version numbers: php -r «phpinfo(INFO_MODULES);» | grep -B 3 -i version > modules.txt

or if you have access to the server configuration file open

and look at all the the extensions,

you can even enable or disable them by switching between On and Off like this

 "; print_r(get_loaded_extensions()); echo "
"; ?> 

the list from php -m is much longer than get_loaded_extensions() which does not list curl, mbstring and many others? why is that? I installed curl, mbstring but they don’t seem to show from the php script?

How to sort get_loaded_extensions() alphabetically? to compare with other working php installs, thank you.

@Meryan I believe you’re seeing a discrepancy between all extensions available (php -m) and the ones actually loaded. (get_loaded_extensions). In your case I believe that means you haven’t enabled curl or mbstring.

If you want to test if a particular extension is loaded you can also use the extension_loaded function, see documentation here

php -r "var_dump(extension_loaded('json'));" 

I particularly like this solution and use it, because it allows my code to check for the required extension and die with a meaningful message. This means the code will tell me if something is wrong, I don’t have to remember. I also add minimum PHP version checks — it’s only a few lines of code.

get_loaded_extensions() output the extensions list.

phpinfo(INFO_MODULES); output the extensions and their details.

I was having the same issue, I needed to know what modules were installed and their version. For now, my solution is to have PHP tell me from the command line. Note, «Core» is PHP.

php -r '$all = get_loaded_extensions(); foreach($all as $i) < $ext = new ReflectionExtension($i); $ver = $ext->getVersion(); echo "$i - $ver" . PHP_EOL;>' 
Core - 7.4.30 date - 7.4.30 libxml - 7.4.30 . mcrypt - 1.0.5 bcmath - 7.4.30 bz2 - 7.4.30 . xml - 7.4.30 xmlwriter - 7.4.30 xsl - 7.4.30 zip - 1.15.6 

Are you looking for a particular extension? In your phpinfo(); , just hit Ctrl + F in your web browser, type in the first 3-4 letters of the extension you’re looking for, and it should show you whether or not its loaded.

Usually in phpinfo() it doesn’t show you all the loaded extensions in one location, it has got a separate section for each loaded extension where it shows all of its variables, file paths, etc, so if there is no section for your extension name it probably means it isn’t loaded.

Alternatively you can open your php.ini file and use the Ctrl + F method to find your extension, and see if its been commented out (usually by a semicolon near the start of the line).

Источник

Оцените статью
Adblock
detector