Created
July 28, 2013 23:37
-
-
Save lancepioch/6100733 to your computer and use it in GitHub Desktop.
Enable or Disable PHP extensions via Bash http://unix.stackexchange.com/questions/66127/is-there-any-command-to-enable-disable-a-php-extension-from-command-line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
php_ini=/path/of/php.ini | |
__module="$2" | |
[[ ! -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; } | |
show_help(){ | |
cat <<_EOF | |
Usage: To enable : | |
$0 -ie <modulename> | |
To disable : | |
$0 -id <modulename> | |
example: | |
$0 -i xyz.so | |
_EOF | |
} | |
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 ;; | |
esac | |
} | |
Main $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment