2

The Problem

I've been trying to setup apache on my mac. I installed apache using brew and everything seems to work except when I actually try to navigate the url with my browser. Anytime I navigate to http://parenting.localhost/ I just get a 404 error. To make things even more odd, if I just go to http://localhost/ (not using the vhost) it still writes the logs to the vhost log files. Clearly something is wrong, I just can't figure it out. Any help would be appreciated.

My Environment

My /usr/local/etc/httpd/extra/httpd-vhosts.conf:

<VirtualHost *:80>
    ServerName parenting.localhost
    ServerAlias parenting.localhost.com

    DocumentRoot "/Users/joshteam/PhpstormProjects/parenting/public"
    <Directory /Users/joshteam/PhpstormProjects/parenting/public>   
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/error.log
    CustomLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/access.log combined
</VirtualHost>

My /etc/hosts:

127.0.0.1       parenting.localhost
127.0.0.1       parenting.localhost.com

I ensure the VHOST is enabled currently:

$ httpd -t -D DUMP_VHOSTS
VirtualHost configuration:
*:80                   parenting.localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:24)

What I'm Trying To Do To navigate to http://parenting.localhost/ and for apache to execute the appropriate index.php within the vhost configuration. Instead I get a 404.

Josh Team
  • 21
  • 2
  • The first configured vhost always acts as a "default host" in an apache http server. So requests that are _not_ handled by any other specialized vhost are handled by that one. This is documented behavior and very important. And it explains why requests to `https://localhost/...` are getting logged to that log file. So most likely you want _two_ vhosts: the default one, typically called "000" or something so that it gets loaded first and then your "parenting.localhost" vhost. – arkascha Dec 14 '22 at 06:45
  • About the `index.php` not getting used: take a look at the ``DirectoryIndex`` directive apache provides. It should indeed contain "index.php". And of course the http process needs read access to those folders and files. – arkascha Dec 14 '22 at 06:46
  • And I recommend to always add the `ServerAlias` for the "www" variant of the hostname, so "www.parenting.localhost" here, maybe along with redirection rules removing the "www." prefix. That is extremely annoying, but some browsers think it is extremely clever to invisibly add a "www." prefix if you manually enter a domain name into your browser. – arkascha Dec 14 '22 at 06:49

0 Answers0