The first step is to install Homebrew and this is a tool (package manager for macOS) that will allow us to install easily PHP and basically any other package/tools.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
To install PHP we can use the command below. The first command will automatically install the latest version of PHP which is at the current moment of writing this post version 8.
brew install php
If other versions may be preferred we can specify the PHP version and the code will look like the following.
brew install [email protected]
The php.ini Config
The default PHP configuration should be sufficient to get started but if there are any other configurations, we can change them through the php.ini located on this path. Do note the PHP version number which in this case is version 8.
To check if PHP is already running we can make use of the brew services command. First, we can list the services that we have installed.
brew services list
If PHP is not started we can then run the command below to start the service in the background.
brew services start [email protected]
Checking PHP Version
Lastly to check the PHP version do run:
By now you will have PHP running on the background process and every time you logged in to the system it will start by default. Thanks for reading and have a good try.