1
votes

I was mainly using XAMPP for my local development needs, but I felt it time to take the crutches off and work from the command line interface.

The issue I am running into is that my virtual hosts are directing to the ServerRoot, and not where the virtual host points. The ones I'm trying currently are laravel apps, so my file structure is

/usr/local/var/www/domain1/laravel

/usr/local/var/www/domain1/public_html

Here is my config files

# /etc/apache2/httpd.conf
ServerRoot "/usr/local/var/www"
ServerName 127.0.0.1
DocumentRoot "/usr/local/var/www"

# /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
      DocumentRoot "/usr/local/var/www/mydomain.com/public_html"
      ServerName dev.mydomain
      ServerAlias www.dev.mydomain
      ErrorLog "/private/var/log/apache2/dev.mydomain/error_log"
      CustomLog "/private/var/log/apache2/dev.mydomain/access_log" common
</VirtualHost>

# /ect/hosts
127.0.0.1   localhost
127.0.0.1   dev.mydomain
::1         localhost
::1         dev.mydomain

When I go to dev.mydomain in the browser, it takes me to /usr/local/var/www instead of /usr/local/var/www/mydomain/public_html

I've already restarted the server.

Edit 1:

When I traverse the file path, the php files are not parsing either and are opening as regular text files.

Edit 2:

I commented the httpd.conf DocumentRoot line out and restarted apache, but the issue persists. When I do a apachectl -t -D DUMP_VHOSTS the Virtual Configuration comes back blank. I have Include /private/etc/apache2/extra/httpd-vhosts.conf uncommented as well as the LoadModule vhost_alias_module.

I changed

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

to

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

but they both link to the same file.

Edit 3:

Doing apachectl -S returns back a different server root than what I established. `apachectl -t -D DUMP_VHOSTS also returns back empty. I think it's possible I might be running a different version of apache than what came default on OSX. I played with it a few years ago. Is there a way to tell where the current running Apache config path is at?

Edit 4:

I checked where the httpd was running and found I have a different apache running than what is default.

MacBook-Pro:extra Daniel$ whereis httpd
/usr/sbin/httpd
Daniels-MacBook-Pro:extra Daniel$ /usr/sbin/httpd -V
Server version: Apache/2.4.29 (Unix)
Server built:   Jan 17 2018 18:20:31
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

I uncommented the vhosts lines again in the other config but now I get an error on restart saying

httpd: Syntax error on line 69 of /usr/local/etc/httpd/httpd.conf: Cannot load lib/httpd/modules/mod_mpm_prefork.so into server: dlopen(/usr/local/var/www/lib/httpd/modules/mod_mpm_prefork.so, 10): image not found

1
comment out DocumentRoot in httpd.confAndra
is there include for the vhosts file in httpd.conf? OK, it is. BUT the path is different. Write the correct path.Andra
I edited, too. The path is different.Andra
@Andra I checked that path, and the /private folder links to the same /etc as what's in the root directory.Dan
btw, then ErrorLog and CustomLog point to non-existent paths?Andra

1 Answers

1
votes

Okay, the issue was that I installed apache a few years ago with Homebrew and forgot. I was configuring the OSX apache config files. To find out which config file is being used, use:

$ whereis httpd
/usr/sbin/httpd
$ /usr/sbin/httpd -V

Server version: Apache/2.4.29 (Unix)
Server built:   Jan 17 2018 18:20:31
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf" <- where you config is, mine wasn't here

The reason the modules were not loading was because I changed the ServerRoot line a long time ago and didn't realize it. The default ServerRoot is /usr/local/opt/httpd, which contains the lib directory, which is where the modules are located and loaded from. Reseting the httpd.conf back to default and looking into that directory before I changed the path was what helped me catch it.