简体   繁体   中英

MacOS Sierra: apachectl is using configuration from /usr/local/etc/apache2/2.4 instead of /etc/apache2/

I have all my configuration files and virtual hosts defined in /etc/apache2/ .

However, when i run apachectl -V i get the following output:

Server version: Apache/2.4.26 (Unix)
Server built:   Jul  8 2017 19:15:17
Server's Module Magic Number: 20120211:68
Server loaded:  APR 1.6.2, APR-UTIL 1.6.0
Compiled using: APR 1.6.2, APR-UTIL 1.6.0
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_SYSVSEM_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/local/Cellar/httpd24/2.4.26"
 -D SUEXEC_BIN="/usr/local/Cellar/httpd24/2.4.26/bin/suexec"
 -D DEFAULT_PIDLOG="/usr/local/var/run/apache2/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/usr/local/etc/apache2/2.4/mime.types"
 -D SERVER_CONFIG_FILE="/usr/local/etc/apache2/2.4/httpd.conf"

This is clearly using some other apache2 config files that I had no idea even exist. How can I force apache2 to use the proper config files?

You likely had an apache installation already on your computer, then installed another version. In this case, you likely have multiple apachectl binaries. Different apachectl binaries will be compiled to be used with different config files.

do:

find /usr -name apachectl

This will find everything in the /usr directory with the name apachectl . My output is:

/usr/local/bin/apachectl
/usr/local/Cellar/httpd/2.4.27/bin/apachectl
/usr/sbin/apachectl

Now look at the information for each executable, using -V, until you find the version compiled with the configuration file you desire:

    /usr/sbin/apachectl -V

out:

    ...
    ...
    ...
    -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

Now we know which one you want to have precedence. So this is how you set precedence.

Even though there are multiple binaries with the same name, when you type in "apachectl" on the terminal, there is no "fight" to determine which one is executed, because precedence is determined by:

  1. the /etc/paths file
  2. your bash profile

You have a few options:

A) (Not recommended) You could change your /etc/paths file to reflect that you'd like one version of apachectl to take precedence over the other

The paths file is for general precedence of entire file hierarchies. You would tell it, "In general, when there are multiple binaries with the same name, execute the one in this directory hierarchy first" . Consequently, the file is very simple and just an ordering of directories. Mine looks like this:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I wouldn't change the paths file because that is sort of like getting rid of a hangnail by ripping off the entire nail.

B) You could change precedence (for a single terminal session) by typing this into your terminal:

export PATH="/usr/sbin/apachectl:$PATH"

This will export a new PATH variable with /usr/sbin/apachectl coming before everything else already in the $PATH . This will prepend the path for your executable to the beginning of the path, making it have precedence over every other possible executable. So when your system gets the call for the apachectl binary from the terminal, it checks the path and stops checking when it comes across a direct path to your executable as the first thing in the Path. This won't stick beyond a single session. So if you close your terminal, the PATH will revert back to what it was.

C) You could make this permanent by adding the previous export command to your ~/.bashrc file (or ~/.bash_profile on a Mac):

export PATH="/usr/sbin/apachectl:$PATH"

Having this in your .bashrc file will cause this statement to be executed everytime you begin a new session, because that is when your profile is read.

If there is another line in your profile that deliberately gives the other version of apachectl precedence, you could either delete it, or just make sure your export... line comes after it in the file.

D) You could make an alias, to refer directly to this executable.

An alias is a word you can use to refer to an executable located in a particular location. Each time you type in your alias, you are referring to that exact executable at that exact location. I recommend doing this above all others:

alias apachectl_a1='/usr/sbin/apachectl'

This also needs to be put in your ~/.bashrc file (~/.bash_profile on Mac) to last beyond a single session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM