Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any command to enable/disable a php extension easily from command line? (php.ini)

share|improve this question
No, but there are tools you can use to parse and modify the config (eg awk). – jordanm Feb 26 '13 at 5:37
just let us know what you configure to disable extension in php.ini so that we can make is easy from command line – Rahul Patil Feb 26 '13 at 6:03
@RahulPatil I just comment extension=x.so to disable x. – PHPst Feb 26 '13 at 6:42

If you are using PHP5.4+ on Debian based distro you can use php5enmod to enable and php5dismod to disable PHP extensions.

share|improve this answer
Note this works by adding/removing links in /etc/php5/{apache2,cli,...}/conf.d/ – Pierre-Olivier Vares Jan 8 at 14:23

You can enable an extension from the command line using:

php -dextension=/path/to/extension.so

-d is used to pass ini values via the command line. Unfortunately there is no way to disable an extension per command line if it has been configured in the php.ini (You can follow the other answers of course but there is nothing you can do using -d or whatever option of the php command)

share|improve this answer

You can simply use

sed -i.bkp 's/^extension=x.so/# extension=x.so/' /path/of/php.ini && /etc/init.d/httpd reload

-i.bkp take backup as php.php.bkp and write in to original file

&& if first command is success then reload httpd service.

but I just notice that sed giving exit status 0 when search patter not match so you can use

grep -q "^extension=$__module" $php_ini && { 
        sed -i.bkp "s/^extension=$__module/# extension=$__module/" $php_ini && 
        echo /etc/init.d/httpd reload; } || echo "cannot make requested change"

Or you can use below script for the enable and disable :



[[ ! -f $php_ini ]] && { echo "Error: Can not found $php_ini" >&2; 
                         echo "Please define php.ini path in $php_ini"; 
                         exit 1; }

[[  -z $__module ]] && { echo "Error: Please Type Module Name:" >&2; 
                          exit 1; }

cat <<_EOF
        Usage:    To enable :
                  $0 -ie  <modulename>

                  To disable :
                  $0 -id  <modulename>

                  $0 -i xyz.so


do_enable() {
grep -Eq "# extension=$__module$" $php_ini && {
sed -i.bkp "s/^# extension\=$__module$/extension=$__module/" $php_ini &&
echo /etc/init.d/httpd reload; echo "Changes Successfully Done"; } || echo "cannot make requested change"

do_disable() {
grep -q "^extension=$__module" $php_ini && {
sed -i.bkp "s/^extension=$__module/# extension=$__module/" $php_ini &&
echo /etc/init.d/httpd reload; echo "Changes Successfully Done"; } || echo "cannot make requested change"

Main() {

case $1 in
        -ie) do_enable ;;
        -id) do_disable ;;
         *) show_help ;;

Main $*
share|improve this answer
Extension could also be added in conf.d/*.ini files. Maybe some modification needs to be done ? – GHugo Mar 28 '13 at 11:21
Yes, we need to do changes for the same, have you tried anything ? – Rahul Patil Mar 28 '13 at 19:11

On Lubuntu I needed pdo_sqlite.

Enable manually:

$ sudo php5enmod pdo_sqlite

If doesn't work check:

$ ls /etc/php5/mods-available

The result list was missing pdo_sqlite.ini. We have to install it.

$ sudo apt-get install php5-sqlite

Or for php7:

$ sudo apt-get install php7-sqlite3

Extension sqlite3 is auto-enabled in CLI and in Apache during installation process, and now we have mods-available: pdo_sqlite.ini, sqlite3.ini.

Disable extension with:

$ sudo php5dismod pdo_sqlite
share|improve this answer

You can specify -n to avoid any extensions loading from php.ini. This can improve some performance when you're using some (e.g. XDebug). E.g.

php -n -r "phpinfo();"
share|improve this answer

You have to use -n and then to append each needed extension using -dextension


php -n -dextension=json.so -dextension=phar.so composer.phar update
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.