php 如何找出 httpd.conf 文件所在的位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13341210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:12:37  来源:igfitidea点击:

How can I find out where the httpd.conf file is located?

phpapache

提问by user1700262

How can I find out the path of the httpd.conf file on apache (PHP)? I do not know whether my script will be runned in windows apache or linux, i need to know where i can find this file in order to find a parameter from there. thanks!

如何在 apache (PHP) 上找到 httpd.conf 文件的路径?我不知道我的脚本是在 windows apache 还是 linux 中运行,我需要知道在哪里可以找到这个文件以便从那里找到参数。谢谢!

回答by lupatus

I think its not exposed to PHP. Run httpd -Vin terminal and you will find it there (command name depends on your system/apache version, it can be also apache -V):

我认为它没有接触到 PHP。httpd -V在终端中运行,您会在那里找到它(命令名称取决于您的系统/apache 版本,也可以是apache -V):

bash-3.2# httpd -V
Server version: Apache/2.2.22 (Unix)
Server built:   Aug 24 2012 17:16:58
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.5, APR-Util 1.3.12
Compiled using: APR 1.4.5, APR-Util 1.3.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -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=128
 -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_LOCKFILE="/private/var/run/accept.lock"
 -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"     <-- HERE IT IS

but if you only want to know the value of some configuration variable then phpinfo(), getenv()or apache_getenv()should be enough

但是如果你只想知道某个配置变量的值,那么phpinfo()getenv()或者apache_getenv()应该就足够了

回答by Ganatra

This is a classic way to locate httpd.conf file:

这是定位 httpd.conf 文件的经典方法:

# find / -name 'httpd.conf' -print

Also you can file locate the file using

您也可以使用文件定位文件

locate httpd.conf

回答by arkascha

Look at the start of the output you get from phpinfo(), the basic apache configuration fodlers are shown there. So easiest is to make a trivial php script and call it once:

查看您从 phpinfo() 获得的输出的开头,那里显示了基本的 apache 配置文件。所以最简单的是制作一个简单的php脚本并调用一次:

<?php phpinfo(); ?>

Likewise you can also directly query these settings. Check the documentation!

同样,您也可以直接查询这些设置。检查文档!

回答by Rajesh

httpd -V

httpd -V

It will shows all compile settings, in the middle of the results you will find:

它将显示所有编译设置,在结果中间你会发现:

  • The Apache root directory:/usr/local/apache
  • The Apache config file pathfrom the root directory: conf/httpd.conf
  • Apache的根目录:/usr/local/apache
  • 根目录下的Apache 配置文件路径conf/httpd.conf

Apache conf file: /usr/local/apache/conf/httpd.conf

阿帕奇配置文件: /usr/local/apache/conf/httpd.conf

root@host [~]# httpd -VServer version: Apache/2.4.16 (Unix) Server built: Dec 15 2015 10:01:02 Cpanel::Easy::Apache v3.32.6 rev9999 Server's Module Magic Number: ... 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 disabled) -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/apache"-D __SUEXEC_BIN="/usr/local/apache/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"

root@host [~]# httpd -VServer version: Apache/2.4.16 (Unix) Server built: Dec 15 2015 10:01:02 Cpanel::Easy::Apache v3.32.6 rev9999 Server's Module Magic Number: ... 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 disabled) -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/apache"-D __SUEXEC_BIN="/usr/local/apache/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"

回答by Dv_

if you are using xampp the file would be in this dir xampp\apache\conf

如果您使用的是 xampp,则该文件将在此目录 xampp\apache\conf 中

回答by Varon

If it isn't listed in phpinfo(), perhaps use

如果它没有在 phpinfo() 中列出,也许使用

apache_getenv(/* variable */)

http://www.php.net/manual/en/function.apache-getenv.php

http://www.php.net/manual/en/function.apache-getenv.php