Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marcelpietsch/3687a0a77a19203d6b867c60d30ae228 to your computer and use it in GitHub Desktop.
Save marcelpietsch/3687a0a77a19203d6b867c60d30ae228 to your computer and use it in GitHub Desktop.
Step 1:
Edit your /etc/hosts file by adding these lines for each project
::1 <projectname>.local
127.0.0.1 <projectname>.local
Replace <projectname> with the name you want. The TLD ending will be .local.
Save.
Step 2:
Edit you /etc/apache2/httpd.conf
Enable the following modules by removing the # before LoadModule on each corresponding line:
deflate_module
expires_module
session_module
ssl_module
rewrite_module
php7_module
Step 3:
Find the lines that say
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
And change that to
DocumentRoot "/Users/<username>/Sites"
<Directory "/Users/<username>/Sites">
where <username> is your macOS user.
Step 4:
Find these lines:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Add one line:
Include /private/etc/apache2/vhosts/*.conf
Step 5:
Find
Group _www
Change to
Group staff
Save.
Step 6:
In /etc/apache2 create a subfolder /vhosts
In that folder create a _default.conf file with this content:
<VirtualHost *:80>
DocumentRoot "/Users/<username>/Sites"
</VirtualHost>
Again, replace the <username>.
Step 7:
In the /vhosts subfolder create a file called <projectname>.local.conf for each project
Add these lines:
<VirtualHost *:80>
DocumentRoot "/Users/<username>/Sites/<projectname>"
ServerName <projectname>.local
ErrorLog "/private/var/log/apache2/<projectname>.local-error_log"
CustomLog "/private/var/log/apache2/<projectname>.local-access_log" common
<Directory "/Users/<username>/Sites/<projectname>">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Again, replace the <username> and <projectname>.
Save.
Step 8:
Create a folder named Sites in /Users/<username>/
It will automatically have the Safari folder icon.
Future projects will be placed there.
/Users/<username>/Sites/<projectname>
Step 9:
Restart apache using this Terminal command:
sudo apachectl restart
Try to open http://<projectname>.local in your browser. It should just work.
You need to restart Apache everytime you add a new vhost.
No https for now. Will update this guide soon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment