Background
I have been using an Apache server with only one site and this has been working really well. My working single-site config is at the bottom of the question. Recently, I have had to create two more sites locally, and I found this guide that showed how to do this. I also referred to this stack overflow question which also helped me a lot.
My problem is that when I visit the three hosts I made in /etc/hosts
and configured in httpd-vhosts.conf
, it is not working and says its-site.test refused to connect.
when I try to visit it in browser.
Attempted Solutions
I attempted to resolve the issue by referring to this stack overflow question which helped me to understand the configuration much better, but it is still not working and results in the same issue.
After spending a few days trying solutions and going through the Apache docs, I opened a new Stack Overflow question and was subsequently directed to this site for further help.
Needless to say I am very new to Apache so I might be overlooking something obvious.
My intended setup
I have three different sites which I want to use named virtual hosts to access in browser during my development process. Rather than using one local host and a few named-based virtual hosts, I wanted all three to be name-based virtual hosts with the below URLs:
- its-site.test
- its-cab.test
- its-gallery.test
If this isn't recommended for some reason, I am flexible on the names, but I wanted to use name-based virtual hosts and three different URLs as the sites are unrelated.
Hosts file
/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 its-site.test
127.0.0.1 its-cab.test
127.0.0.1 its-gallery.test
httpd configuration
/opt/homebrew/etc/httpd/httpd.conf
Listen 80
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
ServerName localhost:80
# Also enabled PHP but not including the config here as it may not be relevant
vhosts configuration
/opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName its-site.test
ServerAlias *.its-site.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-site/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-site/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName its-cab.test
ServerAlias *.its-cab.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-cab/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-cab/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName its-gallery.test
ServerAlias *.its-gallery.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-gallery/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-gallery/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
Question
Does anybody see where I made a mistake with this configuration and can point me towards the solution?
Additional Information
- M1 Macbook Air
- Apache and PHP installed using homebrew
Previous Single Site working Config
As stated earlier, I had this working well when I was serving only one site. My only configuration was with httpd.conf
and did not configure /etc/hosts
or httpd-vhosts.conf
. My working httpd.conf
file looked like:
Listen 80
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-gallery/web"
<Directory "/Users/ciesinsg/Documents/Repositories/its-gallery/web">
# Also enabled PHP
I removed the DocumentRoot
and <Directory>
when I configured VirtualHosts.