Skip to content

Instantly share code, notes, and snippets.

@larrybotha
Last active December 23, 2017 15:17
Show Gist options
  • Save larrybotha/3f448affdbce49c1e5cf to your computer and use it in GitHub Desktop.
Save larrybotha/3f448affdbce49c1e5cf to your computer and use it in GitHub Desktop.

Apache Virtual Hosts Configurations For Mac

Inspired by http://jason.pureconcepts.net/2014/11/configure-apache-virtualhost-mac-os-x/

Install Homebrew Apache

Stop apache, remove launch daemon, install apache from Homebrew.

$ sudo apachectl stop
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
$ brew install httpd24 --with-privileged-ports --with-http2

Copy launchdaemon to launchdaemons folder, set permissions, start apache.

$ sudo cp -v /usr/local/Cellar/httpd24/[your-apache-version]/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
$ sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
$ sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

PHP Installation

$ brew install php55 --with-httpd24
$ brew unlink php55
$ brew install php56 --with-httpd24
$ brew unlink php56
$ brew install php70 --with-httpd24
$ brew unlink php70
$ brew install php71 --with-httpd24

inis are located here:

/usr/local/etc/php/5.5/php.ini
/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini

Enabling SSL For Virtual Hosts

Unsigned SSL: https://getgrav.org/blog/macos-sierra-apache-ssl

Trusted SSL: https://gist.github.com/ethicka/1ba103638d92974487b2

# vhosts/_default.conf
<VirtualHost 0.0.0.0:80>
ServerName localhost
DocumentRoot "/Users/[username]/Server"
</VirtualHost>
# Enable HTTPS
# <VirtualHost *:443>
# ServerName localhost
# DocumentRoot "/Users/[username]/Server"
# SSLEngine on
# SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
# SSLCertificateFile /usr/local/etc/apache2/2.4/server.crt
# SSLCertificateKeyFile /usr/local/etc/apache2/2.4/server.key
# <Directory "/Users/[username]/Server">
# Options Indexes FollowSymLinks
# AllowOverride All
# Order allow,deny
# Allow from all
# Require all granted
# </Directory>
# </VirtualHost>
# vhosts/example.localhost.conf
<VirtualHost 0.0.0.0:80 0.0.0.0:9000>
DocumentRoot "/Users/[username]/Server/[folder-name]"
ServerName example.localhost
ServerAlias example.localhost.*.xip.io
# BrowserSync doesn't seemt o load anything other than .dev domains
ServerAlias example.dev
ServerAlias example.dev.*.xip.io
ErrorLog "/private/var/log/apache2/example.localhost-error_log"
CustomLog "/private/var/log/apache2/example.localhost-access_log" common
<Directory /Users/[username]/Server/[folder-name]>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
# <VirtualHost 0.0.0.0:443>
# DocumentRoot "/Users/[username]/Server/[folder-name]"
# ServerName example.localhost
# ServerAlias example.localhost.*.xip.io
# SSLEngine on
# SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
# SSLCertificateFile /etc/apache2/server.crt
# SSLCertificateKeyFile /etc/apache2/server.key
# <Directory /Users/[username]/Server/[folder-name]>
# Options Indexes FollowSymLinks
# AllowOverride All
# Order allow,deny
# Allow from all
# Require all granted
# </Directory>
# </VirtualHost>
# extra/httpd-mpm.conf
#...
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
# <IfModule !mpm_winnt_module>
# <IfModule !mpm_netware_module>
# LockFile "/private/var/log/apache2/accept.lock"
# </IfModule>
# </IfModule>
#...
# comment out VirtualHost directive in favour of the new one in _default.conf
# extra/httpd-ssl.conf
#...
Listen 443
# <VirtualHost _default_:443>
# ...
# </VirtualHost>
# /usr/local/etc/apache2/2.4/httpd.conf
# SSL/HTTPS stuff (if required)
#...
LoadModule ssl_module libexec/apache2/mod_ssl.so
#...
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
#...
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
# Use generic php modules
#LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
#LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
#LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
#...
User [username]
Group staff
#...
DocumentRoot "/Users/[username]/Server"
<Directory "/Users/[username]/Server">
# ...
AllowOverride All
</Directory>
#...
#<IfModule dir_module>
# DirectoryIndex index.html
#</IfModule>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
# ...
# Virtual hosts
#Include /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf
Include /usr/local/etc/apache2/2.4/vhosts/*.conf
Include /usr/local/etc/apache2/2.4users/*.conf
#...
# Secure (SSL/TLS) connections
Include /usr/local/etc/apache2/2.4/extra/httpd-ssl.conf
# users/[username].conf
<Directory "/Users/[username]/Server/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment