Professional Documents
Culture Documents
macOS 10 - 15 Catalina Apache Setup - MySQL, Xdebug & More... - Official Home of Grav CMS - Part 2 PDF
macOS 10 - 15 Catalina Apache Setup - MySQL, Xdebug & More... - Official Home of Grav CMS - Part 2 PDF
Andy Miller
posted on 10/08/2019 in macos + catalina + apache + homebrew + mysql 12
minutes
In Part 1 of this 3-part series, we covered configuring Apache on macOS to work better with your
local user account, as well as the installation process for installing multiple versions of PHP.
In this Part 2, we will cover installing MySQL, Virtual Hosts, APC caching, YAML, and Xdebug.
After finishing this tutorial, be sure to check out how to enable SSL in Part 3 of the series.
Warning
Tip
This guide is intended for experienced web developers. If you are a beginner developer, you
will be better served using MAMP or MAMP Pro.
MySQL
Although not required for development of Grav, there are times you definitely need an
installation of MySQL. In the original guide, we used the Oracle MySQL installation package.
However, we now have switched to MariaDB which is a drop-in replacement for MySQL and is
easily installed and updated with Brew. Detailed information on the HomeBrew installation
process can be found on the mariadb.org site but the essentials are as follows:
1 $ brew update
2 $ brew install mariadb
After a successful installation, you can start the server ane ensure it autostarts in the future
with:
You must change MySQL server password and secure your installation. The simplest way to do
this is to use the provided script:
1 $ sudo /usr/local/bin/mysql_secure_installation
Just answer the questions and fill them in as is appropriate for your environment. You can just
press return when prompted for the current root password.
Download SequelPro and install it. (it's awesome and free!). You should be create a new
connection via Standard or Socket option after you enter a user of root and your newly
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 2/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
created password.
SequelPro Connection
If you need to stop the server, you can use the simple command:
Apache generally performs name-based matching, so you don't need to configure multiple IP
addresses. Detailed information can be found on the apache.org site.
Apache already comes preconfigured to support this behavior but it is not enabled. First you will
need to uncomment the following lines in your /usr/local/etc/httpd/httpd.conf file:
and:
1 # Virtual hosts
2 Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
Then you can edit this referenced file and configure it to your needs:
1 $ code /usr/local/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.
1 <VirtualHost *:80>
2 DocumentRoot "/Users/your_user/Sites"
3 ServerName localhost
4 </VirtualHost>
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 3/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
5
6 <VirtualHost *:80>
7 DocumentRoot "/Users/your_user/Sites/grav-admin"
8 ServerName grav-admin.test
9 </VirtualHost>
Note
Don't forget to change your_user for your actual username on your Mac. For example:
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
present on the drive. It's an issue that can be resolved by editing this file with the corrected
DocumentRoot .
Dnsmasq
Warning
We used to recommend using .dev domain name, but since Chrome 63 forces all .dev
domains to use SSL, this guide has been updated to use .test
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 4/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
Now you can test it out by pinging some bogus .test name:
1 ping bogus.test
2 PING bogus.test (127.0.0.1): 56 data bytes
3 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.044 ms
4 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.118 ms
5 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.045 ms
Voila! we have successfully setup wildcard forwarding of all *.test DNS names to localhost.
APC Cache
Caching in PHP is a big part of the performance equation. There are two types of caching
typically available, and both have a big impact on speed and performance.
The first type of cache is called an opcode cache, and this is what takes your PHP script 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 quickly
store and retrieve data 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 default, but you can still install
APCu Cache as a data store.
Install APCu
Switch to PHP 5.6 mode, then run the following brew commands to install autoconf :
1 $ sphp 5.6
2 $ brew install autoconf
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 5/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
Then you can install APCu via PECL. PECL is a PHP package manager that is now the preferred
way to install PHP packages. Using it requires a little more manual work than before when these
packages were available via a single one-line brew install command.
For PHP 5.6 we have to install the latest 4.x version of APCu, as this is the last version to
provide PHP 5.6 support:
Tip
Answer any question by simply pressing Return to accept the default values
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
This is probably enough for most people, but if you are like me and like a little more control over
your settings, and also the ability to more easily enable/disable the extension, we have some
extra optional steps.
You will now need to remove the extension="apcu.so" entry that PECL adds to the top of your
php.ini . So edit this file and remove the top line:
1 $ code /usr/local/etc/php/5.6/php.ini
Once that line is removed, we can add a new file with a proper entry to the recently bulit
apcu.so library:
1 $ code /usr/local/etc/php/5.6/conf.d/ext-apcu.ini
1 [apcu]
2 extension="apcu.so"
3 apc.enabled=1
4 apc.shm_size=64M
5
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 6/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
6 apc.ttl=7200
apc.enable_cli=1
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
For PHP 7.0 and above you can use the latest 5.x release of APCu, so the process is the same
for all. First let's switch to PHP 7.0 and install the APCu library:
1 $ sphp 7.0
2 $ pecl uninstall -r apcu
3 $ pecl install apcu
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
Note
The uninstall -r enables PECL to only remove registration, it does not actually uninstall
anything.
Again if you are OK 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 fore each
PHP version.
For PHP 7.1, just repeat these steps but use 7.1 instead of 7.0:
1 $ sphp 7.1
2 $ pecl uninstall -r apcu
3 $ pecl install apcu
1 $ sphp 7.2
2 $ pecl uninstall -r apcu
3 $ pecl install apcu
1 $ sphp 7.3
2 $ pecl uninstall -r apcu
3 $ pecl install apcu
YAML
With recent versions of Grav, we now make use of the native PECL YAML library that allow YAML
processing 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! Luckily this is a simple
process to install for any PHP version:
Switch to PHP 5.6 mode, then run the following brew commands to install libyaml :
1 $ sphp 5.6
2 $ brew install libyaml
For PHP 5.6 we have to install the latest 1.3.x version of YAML, as this is the last version to
provide PHP 5.6 support:
Tip
Answer any question by simply pressing Return to accept the default values
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
For PHP 7.0 and above you can use the latest 2.x release of YAML, so the process is the same
for all. First let's switch to PHP 7.0 and install the YAML library:
1 $ sphp 7.0
2 $ pecl uninstall -r yaml
3 $ pecl install yaml
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 8/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
Note
The uninstall -r enables PECL to only remove registration, it does not actually uninstall
anything.
For PHP 7.1, just repeat these steps but use 7.1 instead of 7.0:
1 $ sphp 7.1
2 $ pecl uninstall -r yaml
3 $ pecl install yaml
1 $ sphp 7.2
2 $ pecl uninstall -r yaml
3 $ pecl install yaml
1 $ sphp 7.3
2 $ pecl uninstall -r yaml
3 $ pecl install yaml
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-"yaml.so" entry in each PHP's php.ini
and instead, create a conf.d/ext-yaml.ini file:
1 [yaml]
2 extension="yaml.so"
Xdebug
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 9/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
One of the most important aspects of any kind of development is the ability to debug and fix
your code. PHP comes with limited support to dump variables or log to a file, but for more
complex situations you need something more powerful.
Xdebug provides is a debugging and profiling extension for PHP that provides an HTML-friendly
output for the var_dump() method that improves the readability of the default version. It also
provides other useful dumping methods as 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 documentation on Xdebug contains
extensive information about all the functionality available. Let's switch back to PHP 5.6 and get
started.
1 $ sphp 5.6
Then you can install Xdebug via PECL. For PHP 5.6 we have to install the latest 2.5.x version of
Xdebug, as this is the last version to provide PHP 5.6 support:
Like the other PECL-installed modules, this will create a simple entry in the php.ini file, but you
really need to configure Xdebug for it to be useful. So let's just go ahead and create our
configuration file as we'll need it shortly anyway.
You will now need to remove the zend_extension="xdebug.so"" entry that PECL adds to the top
of your php.ini . So edit this file and remove the top line:
1 $ code /usr/local/etc/php/5.6/php.ini
Once that line is removed, we can add a new file with a proper entry to the recently bulit
xdebug.so library:
1 $ code /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini
1 [xdebug]
2 zend_extension="xdebug.so"
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 10/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
3 xdebug.remote_enable=1
4 xdebug.remote_host=localhost
5 xdebug.remote_handler=dbgp
6 xdebug.remote_port=9000
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes. You should check the http://localhost/info.php to ensure that Xdebug information is
displayed:
W00fz created a great tool for quickly enabling/disabling xdebug. Install this with brew:
1 $ curl -L https://gist.githubusercontent.com/rhukster/073a2c1270ccb2c686
2 $ chmod +x /usr/local/bin/xdebug
1 $ xdebug
1 $ xdebug on
2 $ xdebug off
Tip
if Xdebug still shows up in php -v the most likely cause is you didn't remove the
zend_extension="xdebug.so"" entry at the top of php.ini
For PHP 7.0 and above you can use the latest 2.7.x release of Xdebug, so the process is the
same for all. First let's switch to PHP 7.0 and install the Xdebug library:
1 $ sphp 7.0
2 $ pecl uninstall -r xdebug
3 $ pecl install xdebug
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 11/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
Afer this just repeat the Required Xdebug Configuration steps, with
/usr/local/etc/php/7.0/php.ini as the PHP configuration file to remove the existing entry, and
/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini for the file you will create with the new Xdebug
configuration.
Restart Apache with the standard sudo apachectl -k restart command to pick up your
changes.
For PHP 7.1, just repeat these steps but use 7.1 instead of 7.0:
1 $ sphp 7.1
2 $ pecl uninstall -r xdebug
3 $ pecl install xdebug
1 $ sphp 7.2
2 $ pecl uninstall -r xdebug
3 $ pecl install xdebug
1 $ sphp 7.3
2 $ pecl uninstall -r xdebug
3 $ pecl install xdebug
Again, repeat the Required Xdebug Configuration steps with the same info you used for 7.2
except use 7.3
Advanced Techniques
Here's a hot tip if you have done this before and want to speed-up the installation process.
Simply install everything ( apcu , yaml , xdebug ) in one shot, and then perform the other non-
installation steps. This is faster but less intuitive for newbies:
PHP 5.6
Copy
1 $ pecl install apcu-4.0.11 && pecl install yaml-1.3.1 && pecl install xd
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 12/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
PHP 7.0+
Repeat the following 2 steps for PHP 7.0 through PHP 7.3:
1 $ sphp 7.0
2 $ pecl uninstall -r apcu && pecl install apcu && pecl uninstall -r yaml
Once you have created your configruation ( conf.d/ext-[lbirary].ini ) files, you can also easily
copy the configuration files from one version of PHP to another.
1 $ cd /usr/local/php/5.6/conf.d
2 $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini ../../7.0/conf.d
3 $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini ../../7.1/conf.d
4 $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini ../../7.2/conf.d
5 $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini ../../7.3/conf.d
You should now be all set with a Rockin' PHP development environment! To find out how to
enable SSL on Apache, check out Part 3 in the series.
Info
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 13/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
0 Comments Grav
1 Login
Name
Related Posts
17
NOV
tutorial
github
As I blogged about the other day, as a web developer, the most efficient and more reliable
Andy Miller 9 minutes
development strategy is to develop locally, then push your local development to your
14
NOV
journal
that site first. Using an efficient development strategy will allow you to build your site
Andy Miller 6 minutes
faster and hassle-free. You might even have fun while doing it!
29
AUG
tutorial
Info
Andy Miller 13 minutes
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 15/16
10/12/2019 macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More... | Official home of Grav CMS
Download Grav
email address
SUBSCRIBE
Crazy Fast VPS Hosting Sponsored by Linode - managed by ServerPilot - monitoring by Pingometer
Copyright @2019 - Grav CMS - All rights reserved - Grav is released under the MIT license
https://getgrav.org/blog/macos-catalina-apache-mysql-vhost-apc 16/16