Proper way to set file permissions

For each parent directory leading to your web root (e.g. ~/my~/my/web~/my/web/root):

  • chmod go-rwx DIR (nobody other than owner can access content)
  • chmod go+x DIR (to allow “users” including _www to “enter” the dir)
  • sudo chgrp -R _www ~/my/web/root (all web content is now group _www)
  • chmod -R go-rwx ~/my/web/root (nobody other than owner can access web content)
  • chmod -R g+rx ~/my/web/root (all web content is now readable/executable/enterable by _www)

 

Taken from http://stackoverflow.com/questions/2001881/correct-owner-group-permissions-for-apache-2-site-files-folders-under-mac-os-x

Adding vhosts in Apache

On a native install on Mac, to add a vhost:

If you haven’t done this one time step, do this first to enable vhosts:

sudo nano /etc/apache2/httpd.conf

Then uncomment the line that includes the vhost config file:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

becomes:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

(Remove # before Include)

Hint: To quickly find the line, use ctrl-w in nano to search for "Virtual hosts"

 

 

Next add an entry to the hosts file

sudo nano /etc/hosts

To add dev.localhost, do this:

127.0.0.1       localhost dev.localhost

Next, do this:

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

Then add a new entry for dev.localhost:
(This is for Apache 2.2)

<VirtualHost *:80>
    ServerName dev.localhost
    DocumentRoot "path goes here"
    ServerAdmin email@domain.com
          <Directory "/path goes here">
                  Options Indexes FollowSymLinks
                  AllowOverride All
                  Order allow,deny
                  Allow from all
          </Directory>
</VirtualHost>

(This is for Apache 2.4)

<VirtualHost *:80>
    ServerName dev.localhost
    DocumentRoot "path goes here"
    ServerAdmin email@domain.com
          <Directory "/path goes here">
                  Options Indexes FollowSymLinks
                  AllowOverride All
                  Require all granted
          </Directory>
</VirtualHost>

[Note the subtle differences between Apache 2.2, and 2.4. More info here ]

 

Also, be sure to remove the two dummy-host entries if they are there. Otherwise, you’ll get a warning about them not being found when you restart apache.