How to Check Which PHP Extensions Have Been Enabled/Disabled in Ubuntu Linux 12.04 Lts

How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS?

Checking for installed php modules and packages

In addition to running

php -m

to get the list of installed php modules, you will probably find it helpful to get the list of the currently installed php packages in Ubuntu:

sudo dpkg --get-selections | grep -v deinstall | grep php

This is helpful since Ubuntu makes php modules available via packages.

You can then install the needed modules by selecting from the available Ubuntu php packages, which you can view by running:

sudo apt-cache search php | grep "^php5-"

Or, for Ubuntu 16.04 and higher:

sudo apt-cache search php | grep "^php7"

As you have mentioned, there is plenty of information available on the actual installation of the packages that you might require, so I won't go into detail about that here.

Related: Enabling / disabling installed php modules

It is possible that an installed module has been disabled. In that case, it won't show up when running php -m, but it will show up in the list of installed Ubuntu packages.

Modules can be enabled/disabled via the php5enmod tool (phpenmod on later distros) which is part of the php-common package.

Ubuntu 12.04:

Enabled modules are symlinked in /etc/php5/conf.d

Ubuntu 12.04: (with PHP 5.4+)

To enable an installed module:

php5enmod <modulename>

To disable an installed module:

php5dismod <modulename>

Ubuntu 16.04 (php7) and higher:

To enable an installed module:

phpenmod <modulename>

To disable an installed module:

phpdismod <modulename>

Reload Apache

Remember to reload Apache2 after enabling/disabling:

service apache2 reload

why aren't PHP extensions built in?

PHP extensions aren't built in because for the most part the PHP team isn't responsible for them. They can be developed by third-party developers.

Also there is a big number of available PHP extensions. Having all of them built into PHP would result in a very large PHP distribution and would increase memory requirements.

Some of them are specific to certain database engines (eg. postgre, oracle, mysql), while hosting services may only provide one engine like mysql. It wouldn't make sense to include useless extensions.

For the second question, PHP has a function to programmatically check for the presence of a given extension:

extension_loaded()

From the documentation:

bool extension_loaded ( string $name )

Finds out whether the extension is loaded.

Finding out in phpinfo output whether specific extensions are installed is just a matter of Ctrl+F for the text.

PHP extension not built with same debug and thread safe as PHP

Its hard to say what exactly was going wrong, I can only say that the extension was build using a different config than the php version.

I will describe some reproducible steps how to compile a most basic extension with debug symbols within the PHP source folder. The extension contains no code except of some boilerplate code created by ext_skel. It just describes the compilation process on UNIX. It is a shell script, you might execute it.

#!/bin/sh

# Should work for all PHP5 versions
VERSION="5.6.9"

# Download the PHP source code
wget \
--continue "http://de2.php.net/get/php-$VERSION.tar.gz/from/this/mirror" \
-O "php-$VERSION".tar.gz

tar xf "php-$VERSION.tar.gz" && cd "php-$VERSION/ext"

# Create a hello extension from skeletons
./ext_skel --extname="hello"

# Uncomment two lines in ext/hello/config.m4
# Read the comments there and you'll know what I'm doing
sed -ri.original \
-e 's/(dnl )(PHP_ARG_ENABLE\(hello)/\2/' \
-e 's/(dnl )(\[ --enable-hello)/\2/' \
hello/config.m4

# Build PHP and the extension
cd ..
./buildconf --force
./configure \
--enable-debug --enable-maintainer-zts \
--enable-hello=shared
make -j

# Test if it is working
sapi/cli/php \
-dextension=modules/hello.so \
-r 'var_dump(extension_loaded("hello"));'

You can now start to enter code to ext/hello/hello.c and create your extension. If you want to compile the changes you make just issue make without arguments.

Since we've compiled using --debug we you can now use gdb to debug the C code and explore how PHP internally works. To start a debugging session use:

gdb sapi/cli/php
...
(gdb) break main
(gdb) run -dextension=modules/hello.so some.php

Of course you'll mostly set breakpoints into your extension functions rather than in the php main() function once you've added code to the extension. However, this should show the basic steps to get there.

Have fun! :)

gdb


Related Topics



Leave a reply



Submit