Skip to content

Instantly share code, notes, and snippets.

@ngohuytrieu
Last active October 12, 2022 03:24
Show Gist options
  • Save ngohuytrieu/c160abf1cff9d2bbe1a243e42b1368d0 to your computer and use it in GitHub Desktop.
Save ngohuytrieu/c160abf1cff9d2bbe1a243e42b1368d0 to your computer and use it in GitHub Desktop.
Setup apache and config virtual host on macOS

Setup apache and config virtual host on macOS

Since macOS Sierra 10.x apache has been built-in. Run these command to start / restart / stop apache

sudo /usr/sbin/apachectl start
sudo /usr/sbin/apachectl stop
sudo /usr/sbin/apachectl restart
sudo /usr/sbin/apachectl status

DocumentRoot

cd /usr/local/var/www

Apache folder

cd /etc/apache2

Apache config file

sudo nano /etc/apache2/httpd.conf

Config virtual host

Open apache config file

sudo nano `/etc/apache2/httpd.conf`

Find and uncomment httpd-vhosts line

Include /private/etc/apache2/extra/httpd-vhosts.conf

Now add your virtual host configuration into httpd-vhosts.conf file:

<VirtualHost *:80>
    ServerAdmin	admin@localhost
    ServerName	my-domain.local
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

Edit /etc/hosts to add virtual host domain

sudo nano /etc/hosts
# add this domain to hosts file
127.0.0.1 my-domain.local

Restart apache

sudo /usr/sbin/apachectl restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment