Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed May 2, 2020
1 parent 41d65e9 commit 2ff67d4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 23 deletions.
24 changes: 2 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/vendor/
.*
vendor/
node_modules/
npm-debug.log
yarn-error.log

# Laravel 4 specific
bootstrap/compiled.php
app/storage/

# Laravel 5 & Lumen specific
public/storage
public/hot

# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot

storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# php-extensions-toggle
# PHP Extension Toggle
Toggle php extensions from command line

## How it works?
- Search for all .ini files in php directory
- Find line where specified extension loaded
- Add or remove `;` at the beginning of the line
- Try restart `fpm`, `apache` and `brew php`

## Requirements
- Linux or MacOs
- Brew to restart php on mac os
- `service` command to restart php-fpm or apache on linux

## Install
1. ```composer global require xtrime-ru/php-extensions-toggle```

## Usage
```
php-extensions xdebug on
php-extensions xdebug off
php-extensions apcu on
```
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "xtrime-ru/php-extensions-toggle",
"description": "Toggle php extensions from cli",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Alexander Pankratov",
"email": "[email protected]"
}
],
"scripts": {
"post-autoload-dump": [
"cp php-extension.sh /usr/local/bin/php-extension"
],
"post-package-uninstall": [
"rm /usr/local/bin/php-extension"
]
}
}
34 changes: 34 additions & 0 deletions php-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

EXTENSION="$1"
[ "$2" == 'on' ] || [ "$2" == '1' ] || [ "$2" == 'enable' ] && ENABLE=true || ENABLE=false
INI_DIR=$(php --ini | grep 'Configuration File (php.ini) Path:' | sed -E "s/.*: //")

if [ "$EXTENSION" == '' ]; then
echo 'Error: no extension provided'
exit 1;
fi

#toogle extension line in .ini file:
find "$INI_DIR" -type f -name "*.ini" | while read -r FILE; do
if [ "$ENABLE" == true ]; then
sed -i '' -E "s/^;((zend_extension|extension).+$EXTENSION\.so)$/\1/g" "$FILE"
else
sed -i '' -E "s/^((zend_extension|extension).+$EXTENSION\.so)$/;\1/g" "$FILE"
fi
done

#restart fpm
echo 'Restart fpm ...'
PHP_VERSION=$(php -v | grep '^PHP ' | sed -E "s/^PHP ([0-9]\.[0-9]).*$/\1/")
service php"$PHP_VERSION"-fpm restart 2> /dev/null
service php-fpm restart 2> /dev/null

#restart apache
echo 'Restart apache ...'
service apache2 restart 2> /dev/null

#restart on MAC
echo 'Restart brew php ...'
brew services restart php@"$PHP_VERSION" 2> /dev/null

0 comments on commit 2ff67d4

Please sign in to comment.