Introduction
This guide will show you how to set up your macOS Mac or Macbook for PHP website development. This includes all the tools and software applications necessary to develop PHP applications.
The main tools that will be used to set everything up are Homebrew and Cask as they make installation easy as you will soon see.
Setup
This setup will work with any recent version of macOS that could be running on a Mac mini, iMac, or MacBook.
Homebrew
Homebrew is a popular package manager specifically for macOS although it can be used for Linux too since both macOS and Linux are unix-based operating systems.
It's used in the command line so the Terminal application that macOS has pre-installed is required, alternatively another macOS terminal application can be used.
Install Homebrew
To begin installation press the Command and Space keys together to bring up the spotlight search.
Type into the spotlight terminal then press the Enter key to open the application.
The terminal will look like the following screenshot, this will be used to install and manage brew packages.
To install Brew copy the following command, paste it into the terminal application, press Enter, and then wait for Homebrew to install.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew will require Xcode so that might be installed as well during the brew installation.
Setup brew command
The following command will add the brew directory to your zsh profile so the brew command can be used.
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/$(whoami)/.zprofile
To apply the brew command to the current terminal session run the following.
eval "$(/usr/local/bin/brew shellenv)"
Now you can use the brew command.
brew
You should see text output showing a list of brew commands as shown in the screenshot.
Brew is now installed and is now ready to be used.
Package list
Going back to the Homebrew website on the formulae page you can see a full list of packages that are available to be installed with Brew.
If you click the the Browse all formulae link you can view all the brew packages available to install.
Go back to the Formulae page and click on the Browse all casks link to view casks available to install.
The difference between casks and the other packages is that casks are macOS GUI applications such as the Google Chrome web browser.
Package search
On the home page of the Homebrew website, there is a search field available for searching brew packages.
Click on the search field to show the search pop-up.
Type in a package, an example you can type in php and then select the php formulae option.
After selecting the option you will be taken to the PHP formalue page where you can see information about it.
These packages can also be found using the brew search together with the brew info command in the terminal application to view information about the package.
Install packages
The following brew packages to be installed will be for PHP web development so all packages are required even though some packages are used more than others.
Also, some of the chosen packages are personal preferences so feel free to change some of the packages to related alternatives if you prefer those.
PHP
To install PHP run the following brew install command.
brew install php
Run the PHP version command to verify it's installed.
php -v
The output should be similar to the following.
Composer
Use the following to install the PHP package manager Composer.
brew install composer
Run the composer command to verify that it's installed.
composer
The output for the composer command looks like the following.
MySQL
Install MySQL with the below command.
brew install mysql
After installation, the MySQL service needs to be started to use MySQL.
brew services start mysql
To check that MySQL is working log in as the root user.
mysql -u root
Hold down the Control key and then press the Z key to exit out of MySQL.
Node / Node Package Manager
Run the below command to install Node and the NPM.
brew install node
Run the Node version to check it's installed.
node -v
Do the same with NPM as well.
npm -v
Git
Git is required to manage application code so it's a requirement, run brew install git to add it.
brew install git
Check with the Git version command to verify that it's installed.
git -v
Code Editor - Visual Studio Code
Now run the brew install --cask command to install the Visual Studio Code application.
brew install --cask visual-studio-code
The following shows how it looks when opening Visual Studio Code for the first time.
MySQL Client - Sequel Ace
To use a GUI to manage MySQL databases install a MySQL client such as Sequel Ace.
brew install --cask sequel-ace
Open up Sequel Ace and log in to MySQL with the following details.
- Host: 127.0.0.1
- Username: root
Password is blank if not changed after the install MySQL step above.
After logging in you can select a database and then view and manage data, at present the default MySQL data is shown as no PHP application-related databases have been added yet.
API Client - Postman
Install an API client application to run endpoints for APIs, the most popular choice is Postman.
brew install --cask postman
Open Postman and it should load up without any issue.
Web browser - Chrome
Even though MacOS comes with Safari as the default web browser for website development it's recommended to install Google Chrome.
The reason is it's the most popular web browser used by internet users so it makes sense to build websites in that browser first.
Run the following command to install.
brew install --cask google-chrome
After opening Google Chrome you will see the following pop-up, select the options you want and click the Start Google Chrome button.
You can either Sign in or skip sign-in from the next screen.
The web browser is now available and ready to be used.
Conclusion
After going through this guide you will have set up a PHP development environment in your macOS device allowing you to develop PHP applications.
This was done by installing Brew and then using Brew to install packages that make up the software needed for PHP development.
Brew isn't just for development applications as other popular applications like Spotify, Dropbox, Steam, and WhatsApp.