This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Local PHP

How to set up php locally for any platform

Currently, this project expects you to bring your own version of PHP so it can be ran natively. This section will cover how to run PHP like this. Don’t worry, dockerizing php to make all this optional is on the roadmap!

1 - Homebrew

Getting started with Magento CLI and running things locally

Installing with brew is the preferred way to install for most use-cases. Homebrew installs the tool globally, and is updated with every release.

Environment Variables

Exporting the following will peg you to a specific version of php for your instance, using homebrew. This is a makeshift approach that requires direnv or the like, in the future the tool will abstract this away for you.

export MAGECLI_PHP_VERSION=8.1.6
export MAGECLI_PHP_BIN=/opt/homebrew/Cellar/php/$MAGECLI_PHP_VERSION/bin/
export PATH=$MAGECLI_PHP_BIN:$PATH%

Installation

Installing PHP with brew is easy, just trigger:

brew install php@8.1

If you run brew link php@8.1 this will set it as the system-wide default. This seems like it should be fine, but keep in mind tools like magento-cloud require PHP 7.4 at the time of this writing so having the system-wide as that version is usually simpler. See the environment variables section to set this per-directory.

2 - phpbrew

Getting started with Magento CLI and running things locally

Enviroment Variables

This is stubbed out but hasn’t been defined yet, homebrew is the best way to use this tool at this point.

export MAGECLI_PHP_VERSION=8.1.6
export MAGECLI_PHP_BIN=/opt/phpbre/--fixme--/$MAGECLI_PHP_VERSION/bin/
export PATH=$MAGECLI_PHP_BIN:$PATH%

Installation

Installing with phpbrew will also supported. This will compile php with any kind of modules or flags you need. Please review the official Installation Documentation to set this up, but we will summerize below.

# install
curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
chmod +x phpbrew.phar

# Move the file to some directory within your $PATH
sudo mv phpbrew.phar /usr/local/bin/phpbrew

phpbrew init

echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc

phpbrew install 8.1.6 +pdo +mysql