Skip to content

Instantly share code, notes, and snippets.

@ramlev
Last active March 28, 2016 18:31
Show Gist options
  • Save ramlev/bd5d5ed01d0cdf57704b to your computer and use it in GitHub Desktop.
Save ramlev/bd5d5ed01d0cdf57704b to your computer and use it in GitHub Desktop.
My PHP/Apache developing setup on OSX

Homebrew

Install homebrew

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

DNSMasq

brew install dnsmasq

Enable dnsmasq daemon

sudo cp "/usr/local/Cellar/dnsmasq/2.75/homebrew.mxcl.dnsmasq.plist" "/Library/LaunchDaemons"
sudo launchctl load -w "/Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"

Add dns domains

mkdir -p /usr/local/etc/
echo "address=/dev/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
echo "address=/devs/127.0.0.1" >> /usr/local/etc/dnsmasq.conf

Add Localhost to /etc/resolver

sudo -s
sudo mkdir -p /etc/resolver
sudo echo 'nameserver 127.0.0.1' > /etc/resolver/dev
sudo echo 'nameserver 127.0.0.1' >> /etc/resolver/devs

# flush cache
dscacheutil -flushcache

# ensure it works
scutil --dns

Apache

sudo vim /etc/apache2/httpd.conf

Change the line

# LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

To

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

And exit vim

Virtualhost configuration

Edit the file

sudo vim /etc/apache2/extra/httpd-vhosts.conf

Empty the file and insert the code snippet from below.

<Directory "/Users/YOU/www">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /var/log/apache2/access_log vcommon

<VirtualHost *:80>
    VirtualDocumentRoot "/Users/YOU/www/%1/%-2/web"
    ServerName sites.devs
    ServerAlias *.devs
    DirectoryIndex app_dev.php index_dev.php app.php index.php
    ErrorLog "/var/log/apache2/vhost-error_log"
    CustomLog "/var/log/apache2/vhost-access_log" common
    UseCanonicalName off
</VirtualHost>
<VirtualHost *:80>
    VirtualDocumentRoot "/Users/YOU/www/%1/%-2"
    ServerName dev
    ServerAlias *.dev
    DirectoryIndex index.php index.html
    ErrorLog "/var/log/apache2/vhost-error_log"
    CustomLog "/var/log/apache2/vhost-access_log" common
    UseCanonicalName off
</VirtualHost>

File/directory structure

You will access the sites with the following examples. The sites with index.php etc. under the web folder, will be accessed with the tld .devs the other with .dev

http://customer1.site1.dev
http://customer1.site2.devs
http://customer3.site7.devs
www
├── customer1
│   ├── site1
│   │   └── index.html
│   ├── site2
│   │   └── web
│   │       └── index.php
│   └── site3
│       └── web
│           └── app_dev.php
├── customer2
│   ├── site4
│   │   └── web
│   └── site5
└── customer3
    ├── site6
    ├── site7
    │   └── web
    │       └── app_dev.php
    └── site8
        └── web
            └── app_dev.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment