Liviu Hariton
PHP developer
Create multiple local domains on macOS Ventura
Assuming you already have Apache HTTP web server installed locally and have enabled the secure connections (https) to it, you can now start creating multiple local domains for your projects.
By the end of this article, you will be able to create and access local domains like https://mylocaldomain.test
or https://myotherlocaldomain.test
and so on.
First things first: let’s create a new folder on our system that will contain all the virtual host configuration files for our future local domains:
$ mkdir /usr/local/etc/httpd/vhosts
$ cd /usr/local/etc/httpd/vhosts
Using your favorite editor, create the configuration file for your first local domain – for example mylocaldomain.test.conf
– and add the following content:
# this will be your regular HTTP configuration
<VirtualHost mylocaldomain.test:80>
ServerName mylocaldomain
ServerAlias mylocaldomain.test
DocumentRoot "/path/to/your/project"
<Directory "/path/to/your/project">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "/path/to/folder/to/store/logs/mylocaldomain.test-error_log"
CustomLog "/path/to/folder/to/store/logs/mylocaldomain.test-access_log" common
</VirtualHost>
# this will be your HTTPS configuration
<VirtualHost mylocaldomain.test:443>
ServerName mylocaldomain
ServerAlias mylocaldomain.test
DocumentRoot "/path/to/your/project"
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
<Directory "/path/to/your/project">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "/path/to/folder/to/store/logs/SSL_mylocaldomain.test-error_log"
CustomLog "/path/to/folder/to/store/logs/SSL_mylocaldomain.test-access_log" common
</VirtualHost>
Now, let’s make sure that the above configuration loads when the Apache HTTP web server starts. Open your /usr/local/etc/httpd/extra/httpd-vhosts.conf
file and add the following:
Include /usr/local/etc/httpd/vhosts/mylocaldomain.test.conf
Restart the Apache HTTP web server
$ brew services restart httpd
# or
$ sudo apachectl -k restart
Now you have to edit your hosts
file. Open up a terminal and run the following command:
$ sudo nano /etc/hosts
Inside the hosts
file, add a new line like this one:
127.0.0.1 mylocaldomain.test
save and close the file ( Control+X
/ Y
/ Enter
) .
Now, let’s clear the local DNS cache:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
If everything was okay untill this point, you should now be able to access your new local domain http://mylocaldomain.test or https://mylocaldomain.test.
Repeat the steps / instructions above everytime you want to add / create a new local domain for your new awesome project.