significant : It ‘s critical to select the compensate type of processor your macintosh is using so the instructions below will be accurate. This is because Homebrew uses different paths for Apple Silicon and Intel based hardware. My macintosh is using an Apple Silicon Intel Processor processor .

Part 2: macOS 12.0 Monterey Web Development Environment

In Part 1 of this 3-part series, we covered configuring Apache on macOS to work good with your local anesthetic user explanation, a well as the installation process for installing multiple versions of PHP .
In this Part 2, we will cover installing MySQL, Virtual Hosts, APC hoard, YAML, and Xdebug. After finishing this tutorial, be certain to check out how to enable SSL in Part 3 of the series .
10/29/2021 Updated to reflect macOS 12.0 Monterey and removed PHP 5.6
11/13/2020 Updated to reflect the release of macOS 11.0 Big Sur
12/02/2019 Updated to reflect the latest let go of of PHP 7.4 and the removal of PHP 7.1 from Official tapdance
12/02/2019 Updated to reflect the latest exhaust of PHP 7.4 and the removal of PHP 7.1 from Official tap
10/08/2019 Updated to reflect the passing of macOS 10.5 Catalina
01/10/2019 Updated to add back PHP 5.6 and PHP 7.0 from and external deprecated keg
12/12/2018 Updated to reflect the latest release of PHP 7.3 and the removal of PHP 7.0 from Brew.

This usher is intended for experienced web developers. If you are a novice developer, you will be better served using MAMP or MAMP Pro .


Although not required for development of Grav, there are times you decidedly need an initiation of MySQL. In the original guide, we used the Oracle MySQL installation package. however, we immediately have switched to MariaDB which is a drop-in substitution for MySQL and is well installed and updated with Brew. Detailed information on the HomeBrew initiation process can be found on the site but the essentials are as follows :
Install MariaDB with Brew :

brew update
brew install mariadb

After a successful initiation, you can start the server one ensure it autostarts in the future with :

brew services start mariadb

You should get some positive feedback on that action :

==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)

You must change MySQL server password and secure your facility. The simplest way to do this is to use the provide handwriting :

sudo /opt/homebrew/bin/mysql_secure_installation

just answer the questions and fill them in a is appropriate for your environment. You can good press revert when prompted for the current root password .
Download TablePlus and install it. ( it ‘s amazing and there ‘s a detached adaptation ! ). You should be create a new MySQL joining, give it a mention, a color, and check Use socket option after you enter a User of root and your newly created password .
TablePlus Connection
If you need to stop the waiter, you can use the elementary dominate :

brew services stop mariadb

Apache Virtual Hosts

A very handy development choice is to have multiple virtual hosts set up for you versatile projects. This means that you can set up names such as which sharpen to your Grav apparatus, or for a project-specific URL .
Apache broadly performs name-based match, so you do n’t need to configure multiple IP addresses. Detailed information can be found on the site .
Apache already comes preconfigured to support this behavior but it is not enabled. First you will need to uncomment the follow lines in your /opt/homebrew/etc/httpd/httpd.conf file :

LoadModule vhost_alias_module lib/httpd/modules/

and :

# Virtual hosts
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf

then you can edit this referenced file and configure it to your needs :

code /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf

This file has some instructions already but the important thing to remember is that these rules are matched in order. When you set up virtual hosts, you will lose your older document root, so you will need to add back support for that first as a virtual host .

    DocumentRoot "/Users/your_user/Sites"
    ServerName localhost

    DocumentRoot "/Users/your_user/Sites/grav-admin"
    ServerName grav-admin.test

Do n’t forget to change your_user for your actual username on your Mac. For model : DocumentRoot "/Users/bernard/Sites"
As you set up your .test virtual hosts, you may receive a warning such as Warning: DocumentRoot [/Users/your_user/Sites/grav-admin] does not exist when restarting Apache. This just lets you know that the source directory listed for your virtual hosts is not salute on the drive. It ‘s an issue that can be resolved by editing this file with the corrected DocumentRoot .


We used to recommend using .dev knowledge domain name, but since Chrome 63 forces all .dev domains to use SSL, this template has been updated to use .test
In the example virtualhost we setup above, we defined a ServerName of grav-admin.test. This by default will not resolve to your local machine, but it ‘s much identical utilitarian to be able to setup versatile virtual hosts for development purposes. You can do this by manually adding entries to /etc/hosts always time, or you can install and configure Dnsmasq to mechanically handle wildcard *.test names and forward all of them to localhost ( ) .
first gear we install it with brew :

brew install dnsmasq

then we setup *.test hosts :

echo 'address=/.test/' > /opt/homebrew/etc/dnsmasq.conf

Start it and ensure it auto-starts on boot in the future :

sudo brew services start dnsmasq

And last, add it to the resolvers :

sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver" > /etc/resolver/test'

immediately you can test it out by pinging some bogus .test identify :

ping bogus.test
PING bogus.test ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.044 ms
64 bytes from icmp_seq=1 ttl=64 time=0.118 ms
64 bytes from icmp_seq=2 ttl=64 time=0.045 ms

Voila ! we have successfully setup wildcard forward of all *.test DNS names to localhost .


One of the most important aspects of any kind of development is the ability to debug and fix your code. PHP comes with specify support to dump variables or log to a charge, but for more complex situations you need something more potent .
Xdebug provides is a debug and profiling extension for PHP that provides an HTML-friendly output signal for the var_dump() method that improves the readability of the default interpretation. It besides provides other useful dumping methods ampere well as displaying stack traces. One of the best features however, is the ability to remote debug your code. This means you can set breakpoints, and step through your PHP code inspecting as you go. Full software documentation on Xdebug contains extensive information about all the functionality available .

Xdebug for various PHP versions

There are some compatibility issues we need to take into account, as certain versions of PHP can only run certain versions of Xdebug :

PHP Version Compatible Xdebug version
PHP 7.0 Xdebug 2.7
PHP 7.1 Xdebug 2.9
PHP 7.2+ Xdebug 3.0

To install specific versions of Xdebug we need to switch to the PHP adaptation we want to install it on, then run these commands :

For PHP 7.0
sphp 7.0
pecl uninstall -r xdebug
pecl install xdebug-2.7.2
For PHP 7.1
sphp 7.1
pecl uninstall -r xdebug
pecl install xdebug-2.9.8
For PHP 7.2+

change sphp 7.2 to the interpretation you want to install xdebug for ( from 7.2 to 8.1 )

sphp 7.2
pecl uninstall -r xdebug
pecl install xdebug

Xdebug Configuration

Like the other PECL-installed modules, this will create a simpleton entrance in the php.ini file, but you actually need to configure Xdebug for it to be useful. So let ‘s barely go ahead and create our shape charge as we ‘ll need it concisely anyhow .
You will immediately need to remove the zend_extension="" introduction that PECL adds to the circus tent of your php.ini. therefore edit this file and remove the top line. In this example we will use 7.0 but it ‘s the lapp routine for each version of PHP .

code /opt/homebrew/etc/php/7.0/php.ini

once that line is removed, we can add a newfangled file with a proper entry to the recently bulit library :

code /opt/homebrew/etc/php/7.0/conf.d/ext-xdebug.ini

For Xdebug versions anterior to 3.0 ( internet explorer, PHP 5.6 through PHP 7.1 ) you can paste the following into the file :


however, Xdebug translation 3.0 ( i, PHP 7.2+ ) has a simplified syntax and should look like this :


Restart Apache with the brew services stop httpd; brew services start httpd control to pick up your changes. You should check the http://localhost/info.php to ensure that Xdebug information is displayed :

if Xdebug still shows up in php -v the most likely cause is you did n’t remove the zend_extension=""" entrance at the top of php.ini
Restart Apache with the brew services stop httpd; brew services start httpd control to pick up your changes .

Xdebug Switcher Script

W00fz created a capital tool for cursorily enabling/disabling xdebug. Install this with brew :

curl -L > /opt/homebrew/bin/xdebug
chmod +x /opt/homebrew/bin/xdebug

Using it is simple, you can get the stream state with :


And then turn it on or off with :

xdebug on
xdebug off

CLI Enabled Xdebug

There are times when you want to debug from the CLI, and you can do this by setting an environment variable. My preferable approach is to use a simpleton script that works with all versions of Xdebug. First create a file in your drug user ‘s bin/ folder ( create the booklet if it does n’t already exist ), and call it xdebug.conf then save this :

export XDEBUG_MODE=debug
export PHP_IDE_CONFIG=serverName=localhost
export XDEBUG_CONFIG=idekey=PHPSTORM remote_port=9000 remote_host=localhost remote_enable=1 remote_handler=dbgp

then ensure it ‘s feasible :

chmod +x ~/bin/xdebug.conf

then when you need to debug, plainly run it whenever you need it :


APC Cache

Caching in PHP is a adult separate of the performance equation. There are two types of caching typically available, and both have a big impact on speed and performance .
The beginning type of cache is called an opcode cache, and this is what takes your PHP handwriting and compiles it for faster execution. This alone can typically result in a 3X speed increase! .
The second type of cache is a user cache, and this is a data-store that PHP can use to promptly store and retrieve datum from. These typically run in memory which means they are transient, but very fast .
All PHP packages now come pre-built with Zend OPcache by nonpayment, but you can still install APCu Cache as a datum store .

Install APCu

switch to PHP 7.0 mood, then run the following brew commands to install autoconf :

sphp 7.0
brew install autoconf

then you can install APCu via PECL. PECL is a PHP package director that is now the prefer way to install PHP packages. Using it requires a little more manual work than earlier when these packages were available via a unmarried one-line brew install instruction .
For PHP 7.0 and above you can use the latest 5.x release of APCu, so the process is the like for all. First lease ‘s switch to PHP 7.0 and install the APCu library :

sphp 7.0
pecl install apcu

Answer any question by plainly pressing Return to accept the default values
Restart Apache with the brew services stop httpd; brew services start httpd command to pick up your changes .

[Optional] APCu Configuration

This is credibly enough for most people, but if you are like me and like a little more command over your settings, and besides the ability to more easily enable/disable the extension, we have some excess optional steps .
You will immediately need to remove the extension="" entrance that PECL adds to the top of your php.ini. so edit this file and remove the lead line :

code /opt/homebrew/etc/php/7.0/php.ini

once that line is removed, we can add a new file with a proper entry to the recently built library :

code /opt/homebrew/etc/php/7.0/conf.d/ext-apcu.ini

In this file paste the following :


Restart Apache with the brew services stop httpd; brew services start httpd command to pick up your changes .

APCu for other PHP versions

For PHP 7.1 do the following :

sphp 7.1
pecl uninstall -r apcu
pecl install apcu

The uninstall -r enables PECL to alone remove registration, it does not actually uninstall anything .
again if you are very well with the ACPu defaults, you can leave things as-is, but you can choose to repeat the Optional APCu Configuration steps to create an APCu configuration file bow each PHP version .
For all other versions, just switch to the allow PHP versiona dn run the two pecl commands .


With late versions of Grav, we immediately make practice of the native PECL YAML library that allow YAML process to be done by highly efficient libYAML C library rather than by they Symfony PHP library. This can result in a 5X improvement in YAML processing times ! fortunately this is a bare process to install for any PHP version :
throw to PHP 5.6 manner, then run the surveil brew commands to install libyaml :

sphp 5.6
brew install libyaml

then you can install YAML via PECL .
For *PHP 7.0 we have to install the latest version of YAML :

pecl install yaml

Answer any question by simply pressing Return to accept the default values
Restart Apache with the brew services stop httpd; brew services start httpd control to pick up your changes .

YAML for other PHP versions

First let ‘s switch to PHP 7.1 and install the YAML library :

sphp 7.1
pecl uninstall -r yaml
pecl install yaml

Restart Apache with the brew services stop httpd; brew services start httpd command to pick up your changes .
The uninstall -r enables PECL to only remove adjustment, it does not actually uninstall anything .
and for all early versions merely repeat the steps above after switching to the appropriate adaptation of PHP.

[Optional] YAML Configuration

If you are feeling adventurous, or you like to keep things uniform, you can follow the same procedure as APCu and remove the default extension-"" entry in each PHP ‘s php.ini and rather, create a conf.d/ext-yaml.ini file :


You should now be all set with a Rockin’ PHP growth environment ! To find out how to enable SSL on Apache, check out Part 3 in the series .
eminence : The brew facility actually creates configuration files in /opt/homebrew/etc/php/5.6/conf.d, /opt/homebrew/etc/php/7.0/conf.d, /opt/homebrew/etc/php/7.1/conf.d, /opt/homebrew/etc/php/7.2/conf.d, /opt/homebrew/etc/php/7.3/conf.d, and /opt/homebrew/etc/php/7.4/conf.d respectively. If you want to uninstall a PHP extension, simply rename the .ini file to .ini.bak and restart apache. alternatively, you can just use brew to uninstall it, and reinstall it again when you need it .

informant :
Category : Website hosting

Leave a Reply

Your email address will not be published.