Apache, MySQL & PHP on macOS Big Sur
01 Nov 2020Apple macOS 11.0 ships with both a relatively recent version of Apache (2.4.x), as well as PHP (7.3.x), so you’ll just have to install MySQL and go through a few steps to get everything up and running.
Big Sur will likely be the last version of macOS that ships with PHP. Apple added the following deprecation warning: PHP is included in macOS for compatibility with legacy software. Future versions of macOS will not include PHP.
Apache
First, you have to create a web root in your user account:
mkdir ~/SitesThen add a configuration for your user:
sudo tee /etc/apache2/users/$USER.conf <<EOF
<Directory "$HOME/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
EOFNow we have to make sure that our user config above actually gets loaded:
sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/users/*.conf
EOFIf you want to use vhosts, you’ll also have to make sure that the vhosts config gets loaded:
sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/extra/httpd-vhosts.conf
EOFAfter that, configure vhosts as necessary in /etc/apache2/extra/httpd-vhosts.conf (don’t forget to remove the examples in there).
It seems that mod_rewrite no longer gets loaded by default, so we’ll also add that to our config:
sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
EOFPHP
PHP doesn’t get loaded by default. So we’ll also add it to our config:
sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule php7_module libexec/apache2/libphp7.so
EOFYou should also configure a few settings in /etc/php.ini:
sudo tee -a /etc/php.ini <<EOF
date.timezone = "`sudo systemsetup -gettimezone | awk '{print $3}'`"
display_errors = on
error_reporting = -1
EOFTo activate these settings you have to restart Apache:
sudo apachectl restartIf you also need PEAR/PECL, follow these instructions.
MySQL
MySQL is not shipped with macOS, so we’ll have to install that manually. Instead of going for an installer package, we’ll use Homebrew. Once Homebrew is installed, installing MySQL is as simple as:
brew install mysqlIf you want to start MySQL automatically, run:
brew services start mysqlAny comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻