Setting up Boris on macOS

Boris is a great little REPL (read-eval-print loop, aka interactive shell) for PHP. It allows you to quickly test and try out PHP code in the terminal.

Boris is fairly straightforward to setup and run on Linux, but chances are, you, like me, have never paid much attention to or even tried to use the PHP version that ships with OS X. And it seems like OS X’s PHP is lacking a few features, so you need to follow a few extra steps to get all of this up and running.

Installing Boris

Install Boris using your preferred installation method. I installed it via git. In your terminal, type the following:

Boris is a great little REPL (read-eval-print loop, aka interactive shell) for PHP. It allows you to quickly test and try out PHP code in the terminal.

Boris is fairly straightforward to setup and run on Linux, but chances are, you, like me, have never paid much attention to or even tried to use the PHP version that ships with OS X. And it seems like OS X’s PHP is lacking a few features, so you need to follow a few extra steps to get all of this up and running.

Installing Boris

Install Boris using your preferred installation method. I installed it via git. In your terminal, type the following:

Installing a newer PHP version and setting Boris to use it

Try to run the REPL now by typing ./bin/boris

This will produce an error message Fatal error: Call to undefined function Boris\pcntl_signal(). If it doesn’t, then you’re good to go – your PHP version already includes all the necesarry functions and Boris should start up immediately. If that’s the case, you can still follow along to make a global alias for easy access. Otherwise, install the latest version of PHP from the PHP for OS X page. I used the 5.4 version personally. It will install PHP to your /usr/local/php5 dir. Now, we need to modify Boris to run PHP with our updated PHP version. Type this in your terminal:

vim bin/boris

Double-press the d key on your keyboard to delete the first line. Then, press i to enter INSERT mode in vim. Paste the following at the beginning of the file:

#!/usr/local/php5/bin/php

Hit escape, and then type :wq to save your file and quit vim. You should now be able to run Boris by typing ./boris

Making boris easily accessible in the terminal

Now probably, you don’t want to have to cd in the BORIS directory everytime you want to run it. In your terminal, run

vim ~/.bash_profile

Use i to enter insert mode again and type the following:

alias boris="cd ~/Library/Developer/boris/bin/ && ./boris"

Make sure to replace ~/Library/Developer/boris/bin/ with the actual directory where you installed/cloned BORIS. Now just open a new terminal window and type boris to run it.