Skip to content
/ p-a-w Public

Php Any Where - Run PHP. Any version. Without install.

License

Notifications You must be signed in to change notification settings

yannoff/p-a-w

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

P A W

Run PHP. Any version. Without install.

Get it

Important note: This script is designed to run on Linux and requires docker to be installed.

Get the latest release from github...

# $BINDIR may be any of the $PATH directories, eg: ~/bin, /usr/local/bin, etc... 
curl -Lo $BINDIR/php https://github.com/yannoff/p-a-w/releases/latest/download/php
# Make the main script executable
chmod +x $BINDIR/php

...add support for the desired php versions

ln -s $BINDIR/php $BINDIR/php5.6
ln -s $BINDIR/php $BINDIR/php7.4
ln -s $BINDIR/php $BINDIR/php8.0

..and that's it !

How it works

Based on the multi-call binary principle (as the well-known BusyBox project) , each php<version> (1) file is just a symlink pointing to the main php entrypoint script: PHP version is deduced from the invoked filename.

(1) If invoked without any suffix, the default version will be used: either the PHP_VERSION env var (if set), the latest GA release (currently 8.3) otherwise.

Hence, adding support for a PHP version is dead-simple: just create a new php<version> (2) symlink to the main php script.

For example:

# Assume ~/bin is in the $PATH system-wide environment variable
~/bin $ ln -s php php7.4
# Now PHP 7.4 can be accessed from everywhere in the system
~/bin $ cd /some/other/path
/some/other/path $ php7.4 --version
PHP 7.4.28 (cli) (built: Mar 29 2022 03:52:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

(2) Version must be one of the following: 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3

Examples

The following examples are given assuming that:

  • The php multi-call script is in one of the $PATH dirs
  • A symlink to it has been created for each php version

Open a php interactive command prompt

Open a PHP 8.0 interactive shell in the current directory

php8.0 -a

Open a bash session

Open a PHP 8.2 container-secluded bash session, with access to the current directory

php8.2

Customizing

The following environment variables allow to fine-tune the PAW script behaviour

Name Description Fallback value
PHP_VERSION The default version to use for PHP 8.3
PAW_IMAGE PHP docker image to leverage yannoff/php-fpm (3)
PAW_DEBUG If set, turn on debug mode -

(3) Based on Alpine, this image uses musl-libc, which implementation differs from glibc on some aspects.

Credits

Licensed under the MIT License.