Skip to content

Instantly share code, notes, and snippets.

@slax0rr
Last active December 17, 2016 09:35
Show Gist options
  • Save slax0rr/08ac75f6ecfa42a1fc93465f3110c36a to your computer and use it in GitHub Desktop.
Save slax0rr/08ac75f6ecfa42a1fc93465f3110c36a to your computer and use it in GitHub Desktop.
Eliminate the need of installing PHP locally, and "re-route" all PHP commands to a PHP enabeld container. Control the version at which PHP is executed through environment variables. Defaults to 7.0
#!/bin/bash
#
# Run all PHP commands through a docker container
#
VER=${PHPVERSION:-7.0-cli}
ARGS="-a"
if [ $# -gt 0 ]; then
ARGS="$@"
fi
docker run -it --rm -v $(pwd):/code -w /code php:$VER php $ARGS
~  php -v
PHP 7.0.14 (cli) (built: Dec 9 2016 18:05:09) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
~  export PHPVERSION=5.6-cli; php -v
PHP 5.6.29 (cli) (built: Dec 14 2016 15:51:03)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
~  export PHPVERSION=7.1-cli; php -v
PHP 7.1.0 (cli) (built: Dec 14 2016 14:48:33) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
~  export PHPVERSION=; php -v
PHP 7.0.14 (cli) (built: Dec 9 2016 18:05:09) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment