在Mac OS X Mountain Lion上编译apache2的问题。

23

我在我的Mac(10.8)上尝试编译最新版本的Apache Web服务器(2.4.3),但遇到了问题。当我运行./configure命令时,我得到了以下输出:

checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-apple-darwin12.0.0
checking host system type... x86_64-apple-darwin12.0.0
checking target system type... x86_64-apple-darwin12.0.0
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc"
  setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -E"
  setting CFLAGS to " "
  setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no
configure: error: in `/Users/cti/Downloads/Applications/httpd-2.4.3':
configure: error: C compiler cannot create executables
See `config.log' for more details

这是日志文件中的最后几行:

## ----------- ##
## Core tests. ##
## ----------- ##

configure:3056: checking for chosen layout
configure:3058: result: Apache
configure:3861: checking for working mkdir -p
configure:3877: result: yes
configure:3886: checking for grep that handles long lines and -e
configure:3944: result: /usr/bin/grep
configure:3949: checking for egrep
configure:4011: result: /usr/bin/grep -E
configure:4027: checking build system type
configure:4041: result: x86_64-apple-darwin12.0.0
configure:4061: checking host system type
configure:4074: result: x86_64-apple-darwin12.0.0
configure:4094: checking target system type
configure:4107: result: x86_64-apple-darwin12.0.0
configure:4137: 
configure:4139: Configuring Apache Portable Runtime library...
configure:4141: 
configure:4182: checking for APR
configure:4327: result: yes
configure:4587: 
configure:4589: Configuring Apache Portable Runtime Utility library...
configure:4591: 
configure:4628: checking for APR-util
configure:4707: result: yes
configure:4968: checking for gcc
configure:4995: result: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
configure:5224: checking for C compiler version
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc --version >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -v >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -V >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -qversion >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5264: checking whether the C compiler works
configure:5286: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc    -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK   conftest.c  >&5
./configure: line 5288: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5290: $? = 127
configure:5328: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:5333: error: in `/Users/cti/Downloads/Applications/httpd-2.4.3':
configure:5335: error: C compiler cannot create executables
See `config.log' for more details

如您所见,日志记录显示在./configure脚本中找不到我的C编译器的路径,因为它位于/Applications/Xcode.app/Contents/Developer/usr/bin/cc而不是日志输出所述的/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc

你可能会说解决方案很简单,我只需要修改configure脚本,对吧??好吧,问题在于我对shell脚本一无所知,这就是为什么我已经苦苦挣扎了3个小时。

请求帮助。提前致谢。


是的,我尝试过了,但里面没有任何能帮助我的东西。 - Codejunky
这样也许可以帮助我们帮助您?请编辑您的问题,将日志文件的最后几行包含在内。 - Some programmer dude
我按照你的要求添加了日志文件的最后几行,请查看并告诉我你的想法。 - Codejunky
10个回答

53

1
非常感谢Adrian,你刚刚救了我的命 :) - Codejunky
1
看起来在Mountain Lion中,APR-Util / APR(用于编译基于共享库的不同产品的便携式环境)出现了问题。它链接到错误的编译器。有人知道如何切换吗?例如,对于apxs,您可以运行apxs -c -S cc = / usr / bin / gcc等。 - JonMorehouse
太棒了的提示!救星! - RubyFanatic
1
有时候需要将OSX10.8替换为OSX10.9以适配Maverick。 - Thierry M.S.
1
在环境设置的黑暗森林中,我找到了你的拯救生命的一线光明 :) 谢谢。 - Benyamin Shoham
显示剩余2条评论

11

对于OSX 10.9 Mavericks,Apache已经安装完毕,您可以直接进入终端并输入以下命令

查找Apache版本

httpd -v

开始:

sudo apachectl start 
停止:
sudo apachectl stop
重新开始:

要重新开始:

sudo apachectl restart

9

我使用的操作系统是OSX Mavericks,正在尝试编译Apache 2.2.24版本时遇到了错误。通过查看其他答案,我发现问题出在apxr和APR返回gcc错误的位置上。苹果公司提供了gcc,而Apache配置文件使用的是苹果公司提供的gcc。

突发奇想,我发现configure脚本有一个选项可以忽略系统提供的APR并使用自己的APR。

因此,我执行了以下操作:

./configure --with-included-apr

它已经通过了配置步骤并且编译时没有出现错误。


为了使其正常工作,您需要下载Apache APR库。例如:cd srclib/; curl http://wwwftp.ciril.fr/pub/apache//apr/apr-1.5.1.tar.gz | tar xvz; curl http://wwwftp.ciril.fr/pub/apache//apr/apr-util-1.5.4.tar.gz | tar xvz; mv apr-1.5.1 apr; mv apr-util-1.5.4 apr-util; cd apr; configure; make; cd .. ; cd apr-util; configure; make; cd .. ; cd .. - Max

2

OSX Yosemite(10.10.5)

对我来说,接受的答案起了作用:

$ cd /Applications/Xcode.app/Contents/Developer/Toolchains

$ ln -s XcodeDefault.xctoolchain/ OSX10.10.xctoolchain
                   ^                      ^
                   |                      |
             existing dir(or file)     link name

(下面是为什么这有效的解释。)
然后:
httpd-2.4.18$ ./configure  (php may require an additional option)

如果您还要安装PHP,您可能需要在./configure中添加另一个选项。 在Unix上安装PHP的基本说明也提供了有关如何安装Apache的说明:
./configure --enable-so
make
make install

Apache的配置帮助说道:
httpd-2.4.18$ ./configure --help 
...
...
--enable-so    DSO capability. This module will be automatically
               enabled unless you build all modules statically.

这似乎表明--enable-so选项可能是默认选项,但是Apache安装说明甚至没有提到--enable-so。在Apache 2.2文档中的configure中,我找到了这个:
Modules, disabled by default
Some modules are compiled by default and have to be enabled explicitly...
...
...
--enable-so
...

"Apache 2.4的配置文档没有提到--enable-so。相反,它们告诉你查看 ./configure --help的输出,在“可选功能”下列出--enable-so。
因此,我认为您应该这样配置apache:"
 httpd-2.4.18$ ./configure --enable-so

========

安装PHP
为了使mysql与php配合使用,我不得不重新安装php并更改php安装文档中的以下行:
php-7.0.2$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql

to:

php-7.0.2$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql

使用第一个选项时,配置输出显示--with-mysql选项不存在,但php安装成功,并且apache的htdocs目录中的php文件可以执行。问题在于php已更改其mysql支持,mysql_connect()已被弃用(并从php7中删除),因此现在需要pdo-mysql适配器,如php文档所述。重新安装php后,make install的最后几行显示如下:
You may want to add: /usr/local/lib/php to your php.ini include_path

"php.ini"文件位于此处:/usr/local/lib/php.ini,我已经进行了更改。"
include_path = ".:/php/includes:/usr/local/lib/php"

然后我重新启动了Apache,确保MySQL正在运行,并在浏览器中输入了以下URL:
http://localhost:8080/mysql_test.php

我的测试PDO脚本已经运行成功(位于目录/usr/local/apache2/htdocs中):
<?php

$user = 'root';
$password = ’root_password_here’;
$host = 'localhost';
$dbname = 'my_db';


$pdo = new PDO(
    "mysql:host=$host; dbname=$dbname", 
    $user,
    $password
);

$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);

?>

===========

在遇到与原帖相同的错误信息后,我检查了httpd-2.4.18目录下的config.log文件,在其中发现一行内容如下:
./configure: line 5326: /Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/cc: 
No such file or directory

因此,配置脚本正在寻找以下内容:
  1. 名为:

    /Applications/Xcode.app/Contents/Developer/ Toolchains/OSX10.10.xctoolchain/usr/bin/

    的目录。
  2. 该目录下的名为cc的文件。

好的,让我们看看那个目录中是否有cc文件:

~$ cd/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/

-bash: cd: /Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/: No such file or directory

这意味着该目录不存在。现在你必须找出在那条长路径中哪个目录不存在:
~$ cd /Applications/Xcode.app
/Applications/Xcode.app$ cd Contents/Developer
/Applications/Xcode.app/Contents/Developer$ cd Toolchains/OSX10.10.xctoolchain

-bash: cd: Toolchains/OSX10.10.xctoolchain/: No such file or directory

/Applications/Xcode.app/Contents/Developer$ cd Toolchains
/Applications/Xcode.app/Contents/Developer/Toolchains$ ls 

XcodeDefault.xctoolchain

您可以看到,没有名为OSX10.10.xctoolchain的目录 - 只有一个名为XcodeDefault.xctoolchain的目录。 因此,configure脚本无法在其用于查找cc文件的路径中定位目录OSX10.10.xctoolchain。为什么configure要寻找该目录?因为编写脚本的开发人员出了问题或者苹果公司出了问题。 configure的真正目标不是查找目录,而是查找顽固的cc文件。原来cc文件位于此处:
/Applications/Xcode.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin$ ls
...
cc
clang       
...
...

"而对于更好奇的人:"
/Applications/Xcode.app/Contents/Developer/
Toolchains/XcodeDefault.xctoolchain/usr/bin$ ls -al cc

lrwxr-xr-x  1 7stud  admin  5 Oct 29 15:22 cc -> clang

"

cc只是指向Xcode的clang编译器的链接。

接受的答案将名称为OSX10.10.xctoolchain的链接创建到实际包含cc文件(尽管在几个目录深处)的目录XcodeDefault.xctoolchain

"
Applications/
  Xcode.app/
    Contents/
      Developer/
        Toolchains/
          XcodeDefault.xctoolchain/
          OSX10.10.xctoolchain/ -> XcodeDefault.xctoolchain/
            usr/
              bin/
                 cc 

换句话说,在创建链接后,这两条路径:
/Applications/Xcode.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin

/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin

将等价。名称 XcodeDefault.xctoolchainOSX10.10.xctoolchain 将成为同一目录的别名。

====

我不理解@AlphaZygma的回答。它建议将以下两个目录添加到您的PATH中(通过/etc/paths):
/Applications/Xcode.app/Contents/Developer/usr/bin

/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.8.xctoolchain/usr/bin

在我的系统上,第一个目录中没有包含cc文件,所以我没有理由将该目录添加到我的PATH中。
第二个目录是configure无法找到的目录。将不存在的目录添加到您的PATH中仍然意味着它不存在。
无论如何,configure脚本似乎没有在PATH目录中搜索cc,因为错误消息列出了一个不存在的路径作为问题。搜索PATH目录如何导致错误消息列出一个不存在的路径?configure脚本似乎从其他地方获取指示,告诉它在哪里搜索cc
我不确定为什么@AlphaZygma在/etc/paths中的一些现有路径之间插入了新路径。为什么不在现有路径下方添加新路径呢?

====

我查看了 ./configure --help 的输出:
Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

...
...

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

“嘿,CC在那里列出来了。让我们试一试:”
$ ./configure CC=/Applications/Xcode.app/Contents/Developer/
Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

...
...

checking for APR... yes
  setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc -E"
  setting CFLAGS to " "
  setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10"
  setting LDFLAGS to " "
configure: 
...
...
configure: error: C compiler cannot create executables

仔细查看输出,有这样一行:

      setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain 

配置脚本仍然与CPP一起提到了不存在的路径。再次查看./configure --help的输出:
Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

...
...

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

最后一行列出了在错误行中提到的变量CPP。让我们尝试:
$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc 

...
...

checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
configure: error: in `/Users/7stud/Downloads/httpd-2.4.18':
configure: error: C preprocessor "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" fails sanity check
See `config.log' for more details

现在错误消息中所有路径都是正确的,但是有些地方“未通过健全性检查”。我放弃了!也许其他人可以接着我进行。

好的,多亏了这里的建议,下面的代码可以工作:。

$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -E'

这可以缩短为:
$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP='cc -E'

但是然后make失败了:
$ make
...
/usr/share/apr-1/build-1/libtool: line 8962: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc: No such file or directory

再次提到了不存在的路径,这次是与 libtool 相关联。我不会深入探究这个问题。

2
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc accepts -g... yes
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc option to accept ISO C89... none needed
checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -E
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc option to accept ISO C99... none needed
checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

====

我已经下载了pcre-config,并运行了:./configure;make;make install

现在...... Tcharammmm!Httpd apache完整安装:D


1
这是对这个问题的回答还是另一个问题以及您解决它的方式?如果是后者,请将其作为不同的问题发布,并添加您自己的答案。 - Harry

1
遇到了同样的问题,在Mac OS X 10.9(Mavericks)上;正如user3097424所说,Apache已经预装在Mavericks用户中,但对于我来说,版本是2.2。因此,需要升级到2.4,按照Adrian Rodriguez所说的做法创建符号链接,将“10.8”替换为“10.9”:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain

0

完整的解决方案让我顺利通过:

checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no

问题可以在这里找到: http://mac-dev-env.patrickbougie.com/apache/ 命令如下(有些需要sudo su):
cd /usr/local/src (mkdir /usr/local/srt if /usr/local/src doesnt exist)
curl --remote-name http://mirror.csclub.uwaterloo.ca/apache/httpd/httpd-2.4.9.tar.gz
tar -xzvf httpd-2.4.9.tar.gz
rmhttpd-2.4.9.tar.gz
cd httpd-2.4.9

sudo xcode-select -switch /
mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin (this might require sudo su)
ln -s /usr/bin/cc /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc (this might require sudo su)

./configure --prefix=/usr/local/apache-2.4.9
make
make install

ln -s apache-2.4.9 /usr/local/apache

这基本上是与已接受答案相同的答案。事实证明,cc也位于/usr/bin以及/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/。该答案只是通过符号链接名称/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc,它是配置脚本正在寻找但找不到的内容,将其链接到现有的 /usr/bin/cc而不是/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - 7stud

0

@AlphaZygma,这对我非常有用。我使用的是10.8.5版本,需要将以下内容添加到/etc/paths中:

/Applications/Xcode.app/Contents/Developer/usr/bin
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

使用这个而不是你的。


OSX Yosemite(10.10.5):第二个目录对我来说是存在的,但我不确定这如何使configure在该目录中查找cc而不是不存在的目录:/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/b‌​in/,这是config.log显示导致我的错误的原因。 - 7stud

0

不必创建符号链接,您可以将路径添加到库路径中,只需使用适用于您的OSX版本的相应目录即可。

因此,在您的情况下,可能如下所示:

[user@host ~]$ sudo vi /etc/paths
/usr/bin
/Applications/Xcode.app/Contents/Developer/usr/bin
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin
/bin
...

我认为这种方法更加简洁,而不需要在不同的位置添加符号链接以满足不同的工具的期望。

无论如何,这只是一种替代方案。

希望这能有所帮助。


OSX Yosemite(10.10.5): 在遇到与操作者相同的错误后,我检查了httpd-2.4.18目录下的config.log文件,它显示:./configure: line 5326: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc: No such file or directory。我不确定将不存在的目录添加到我的PATH中如何帮助配置脚本找到cc文件。 - 7stud

0

我最近刚升级到Mavericks,并重新创建了我的Web开发环境(包括安装端口)。在升级端口时,我遇到了这个问题:

checking whether the C compiler works... no

我本以为我已经做好了一切准备,包括从应用商店安装 XCode。但是问题一直存在。我通过实际运行 XCode 一次,接受许可协议并完全启动 XCode,成功解决了这个问题。下次尝试升级端口时,我没有再遇到上述错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接