DEV Community 👩‍💻👨‍💻

Alex Crivion
Alex Crivion

Posted on

Autogenerate VHOSTS on macOS X

Every time I wanted to activate a new virtual host on my local macOS machine for development

I had to do the regular steps

  1. create directory
  2. create apache vhosts entry
  3. create /etc/hosts entry

So, I have built myself a tool.

  • PHP-cli tool

  • Site Directories must end in .local to be picked up

  • example /path/site.local will become

define('SITES_PATH', '/Users/your-user/Sites');
define('VHOSTS_FILE', '/etc/apache2/extra/httpd-vhosts.conf');
define('HOSTS_FILE', '/etc/hosts');
Enter fullscreen mode Exit fullscreen mode

Usage (must be super user):

sudo php index.php

PHP-Cli Output Example

Alt text

Find out on github:

Feel free to use as you wish.

Top comments (0)

Make Your Github Profile Stand Out

Github is great, but have you considered how to make yours more attractive for potential employers or other visitors? Even non-tech ones like recruiters!

Take a couple of hours and show your best side as a person - and a programmer.