macOS Ventura 13.0 Setup: Homebrew + Apache + PHP + MariaDB
This document helps keep your macOS development environment up and running with the latest Homebrew, Apache, PHP, and MariaDB.
Before we start, if you haven’t already installed XCode Command Line Tools on your system, let’s do that.
$ xcode-select --install
Homebrew is an excellent package manager for macOS. Homebrew installs the stuff you need that Apple (or your Linux system) didn’t; let’s install it.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew can self-diagnose and check your system for potential problems. Let’s see if everything is working the way it should.
$ brew doctor
If the installation is successful, the output will be:
Your system is ready to brew.
Otherwise, please follow the instructions to fix any potential issues.
macOS 13.0 Ventura comes with Apache 2.4 pre-installed. However, we don’t want Apple to control our web server so let’s stop it and prevent it from starting on boot.
$ sudo apachectl stop
$ sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
Type the following command into your terminal to create a new folder in your user’s root directory.
$ mkdir ~/Sites
💡 Tip: macOS automatically adds the compass icon to your folder.
Now, let’s brew and configure our new Apache version. We will update it to run on standard ports (80/443) shortly.
$ brew install httpd
Check the installation path.
$ which apachectl
Set Apache to start now and restart at login.
$ sudo brew services start httpd
💡 Tip: You can monitor the Apache error log in a new Terminal tab/window to see if anything is invalid or causing a problem.
$ tail -f /usr/local/var/log/httpd/error_log
💡 Tip: Remember useful Apache ‘brew services’ commands.
$ brew services stop httpd
$ brew services start httpd
$ brew services restart httpd
Install the latest PHP version.
$ brew install php
The php.ini file can be found in:
Apache PHP Setup
Now that we have PHP successfully installed, we still need to tell Apache to use it. Please edit the Apache
Find Listen 8080 and change the port to 80:
Uncomment the following lines.
LoadModule socache_shmcb_module lib/httpd/modules/mod_socache_shmcb.so
LoadModule ssl_module lib/httpd/modules/mod_ssl.so
LoadModule vhost_alias_module lib/httpd/modules/mod_vhost_alias.so
LoadModule userdir_module lib/httpd/modules/mod_userdir.so
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Add the following entry at the end of the LoadModules section.
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
Update User and Group where your_username is the name of your User in macOS and Group will be “staff.”
Servername is disabled by default; set it to localhost:
Let’s modify httpd.conf a bit more. Change DocumentRoot; it makes up the basic document tree, which will be visible from the web.
Check that directive DirectoryIndex includes
DirectoryIndex index.php index.html
And we need to add the
FilesMatch directive so that Apache will now process PHP files.
Uncomment the following to enable user home directories, virtual hosts, and secure (SSL/TLS) connections.
$ brew services restart httpd
Run a configuration file syntax test to verify/validate the configuration. It reports “Syntax Ok” or detailed information about the particular syntax error. This is equivalent to
sudo apachectl -t.
$ sudo apachectl configtest
If it says “Syntax OK,” open a browser using http://127.0.0.1. You should see a message saying, “It works!”
php -v in the terminal. It should report something like the following.
PHP 8.1.9 (cli) (built: Aug 4 2022 15:12:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.9, Copyright (c) Zend Technologies
with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies
Install MariaDB using Homebrew.
$ brew install mariadb
Let’s have MariaDB start automatically on boot.
$ brew services start mariadb
You will see something like the following.
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)
Improve the security of the installation and change the database’s root password.
$ sudo /usr/local/bin/mysql_secure_installation
You will be prompted with:
Enter current password for root (enter for none):
Press return here.
Change the root password, and continue with the prompts.
Change the root password? [Y/n]
When you get to the following prompt, enter Y to reload privileges.
Reload privilege tables now?
When finished, restart the MariaDB server.
$ brew services restart mariadb
You can now try logging into MariaDB.
mysql -u root -p
If successful, you should see the following.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.5.8-MariaDB HomebrewCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
The OpenSSL software library is a prerequisite to generate a certificate. Check if OpenSSL is available by running the following command in the local environment.
$ which openssl
We need to install OpenSSL if the
which command does not return a path.
$ brew install openssl
Change default 8443 ports to 443 in the SSL configuration file.
$ vi /usr/local/etc/httpd/extra/httpd-ssl.conf
Replace all lines that say ‘8443’ with ‘443’.
ServerName www.example.com:443<VirtualHost _default_:443>
After the file has been saved, follow the prompts to generate a key and a self-signed certificate.
$ cd /usr/local/etc/httpd
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
/usr/local/etc/httpd/extra/httpd-vhosts.conf and add your own SSL-based virtual host entries.
$ vi /usr/local/etc/httpd/extra/httpd-vhosts.conf<VirtualHost *:80>
CustomLog "/usr/local/var/log/httpd/yourprojectname-access_log" common
Finally, in the Terminal window, restart Apache.
$ brew services restart httpd