Setting up Apache Virtual Host with Mac OS

Tired of running your project constantly after you close it for a while... Yes you have come to the right place, in this particular blog, I would guide you how to setting up your VirtualHost with Apache 2 ( using Mac OS 10.11 )


1. Allow the Vhost configuration

- Open the httpd.conf:

sudo nano /etc/apache2/httpd.conf
- Search for 'vhosts' and uncomment:

# Virtual hosts

Include /private/etc/apache2/extra/httpd-vhosts.conf
- And uncomment to allow another module :

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

2. Edit the vhosts.conf file


- Open this file to add virtual host: 

sudo nano /etc/apache2/extra/httpd-vhosts.conf
- Then you can add your virtual host into it :

<VirtualHost *:80>
    ServerName scuti.dev
    ServerAlias www.scuti.dev
    DocumentRoot "/Users/scuti/Sites/scuti"
    ErrorLog "/private/var/log/apache2/apple.com-error_log"
    CustomLog "/private/var/log/apache2/apple.com-access_log" common
    ServerAdmin web@coolestguidesontheplanet.com
</VirtualHost>

3. Map your IP address to localhost:


- Open your /etc/hosts file and simple add domain to localhost:

127.0.0.1 scuti.dev www.scuti.dev

4. Losing Localhost:


You would get 403 internal server error if you try to access scuti.dev now, this is understandable since you need to add in a vhost for localhost and declare this vhost before any of the others in the same files /etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
Then restart your apache by

sudo apachectl restart

5. Folder sharing


If you still get the error of folder sharing, you might have faced the error of configuration file for user

Check if you have a "username.conf" file under /etc/apache2/users, if not create one after your account name 
*Note: if you dont know your account name you can simple find out by typing 'whoami'

Add the content below to your 'username.conf' file

<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
And the permission of the file should look like this:

-rw-r--r--   1 root  wheel  298 Jun 28 16:47 username.conf
Then restart Apache once again

 sudo apachectl restart

6. Directory Setting


If you can not get your virtual host up and running, it maybe due to your global setting in the httpd.conf or specific directory block in httpd-vhosts.conf. You should change from

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
to

<Directory />
    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
Try restarting your apache and you're good to go.










If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Anonymous

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment