Skip to content

PHP Monitor helper binaries

Nico Verbruggen edited this page Aug 14, 2022 · 2 revisions

PHP Monitor can make it easier for you to run terminal commands using a specific version of PHP. Since you can now force specific sites to use a particular version of PHP, sometimes you’ll need to run a command with that version of PHP, too.

Ensuring helpers are generated

PHP Monitor registers these helpers for you, assuming you are permitted to write to the /usr/local/bin folder. Make sure you own the folder first, or the helpers will not be created:

sudo chown "$(whoami)" /usr/local/bin

If you do not want to make this folder writable for security reasons, you may also add the following folder to your PATH (only on PHP Monitor 5.5 and newer): ~/.config/phpmon/bin.

It is usually sufficient to add the following line to your .zshrc file if you want to add PHP Monitor's binaries to your PATH:

export PATH=$HOME/bin:~/.config/phpmon/bin:$PATH

How to use the helper files

Here's how you can use these helpers. First, I recommend you check which version is globally linked:

$ php -v
PHP 8.1.4 (cli) (built: Mar 18 2022 09:32:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.4, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans

This is the globally linked PHP version. Now, let's say we want to use PHP 8.0 in this terminal, from now on. We can source the pm80 helper in that case. (If we wanted PHP 7.4, we'd use pm74.)

You can use the shorthand for source, which is .:

$ . pm80
PHP Monitor has enabled this terminal to use PHP 8.0.

The script includes a little notice, so you'll be able to see that it worked.

Alternatively, you can run source pm80 as well. Any subsequent commands in this particular terminal session will run with that version of PHP, so keep that in mind:

$ php -v
PHP 8.0.17 (cli) (built: Mar 18 2022 09:32:28) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies
    with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

If you run composer update now, it'll use that version of PHP as well. You can close the terminal you have active and open a new terminal to switch back to the globally linked PHP version.

If you'd like to inspect these helpers, you can find them in /usr/local/bin for every PHP version that is available on your system. They are overwritten whenever the app boots.