本节汇集了大多数编译时出现的常见错误。
你必须安装有 GNU 的 autoconf 包,这样才可以从 configure.in生成 configure 脚本。从 CVS 得到源程序后只要在最高层的目录中运行 ./buildconf即可。(同样,除非你用了 --enable-maintainer-mode选项来运行 configure,否则即使 configure.in文件更新了,configure 脚本也不会自动重新生成。所以当你发现 configure.in文件更新了时要确保手工重新生成 configure 脚本。有一个症状是在 configure 之后或者运行 config.status时在 Makefile 中寻找类似 @VARIABLE@ 的东西。)
你需要告诉 configure/setup 脚本你的 Apache 源程序最上层的目录位置。这意味着你需要这样指定 --with-apache=/path/to/apache 而 不是这样 --with-apache=/path/to/apache/src 。
请认真阅读 PHP 的 安装说明,并注意要编译 PHP 需要同时安装 flex 和 bison。根据设置的不同,可以从源代码编译 bison 和 flex,要么通过已编译好的发行包,例如 RPM。
可以通过指定附加的选项让 configure 脚本在非标准的路径中寻找头文件和库并传递给 C 预处理器和连接器,例如:
CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configure
env CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configure
需要更新 Bison 的版本。最新版本在 » http://www.gnu.org/software/bison/bison.html。
一些旧版本的 make 没有正确将 functions 目录下编译后的文件放到同一个目录下。试试运行 cp *.o functions然后再运行 make看看有没有什么帮助。如果成功了,那你确实需要更新到最新版的 GNU make。
看看连接的这一行命令,确认所有适当的库都包括在最后了。通常可能漏掉了“-ldl”和你包括的任何数据库支持所需要的库。
如果和 Apache 1.2.x 一起连接,记得把适当的信息添加到配置文件的 EXTRA_LIBS 这一行并重新运行 Apache 的配置脚本了吗?更多信息见 安装一章。
一些人也报告说在和 Apache 连接时他们不得不紧接着 libphp4.a之后加上“-ldl”。
这其实很简单。小心地照着以下步骤来:
注意:也可以用新的 Apache ./configure脚本。参见 Apache 发行包中 README.configure文件中的说明。也看看 PHP 发行包中的 INSTALL文件。
这说明 PHP 模块出于某些原因没有被调用。在寻求更多帮助前先检查三件事:
注意 libphp4.a文件本来就不该存在,apache 进程将创建它!
这是一个 Apache 误报的错误信息,在新的版本中已经修正了。
这里要检查三件事。首先,出于某些原因当 Apache 生成 apxs Perl 脚本时,有时没有正确的编译和标记变量就结束了。找到你的 apxs 脚本(用命令 which apxs),有时会在 /usr/local/apache/bin/apxs或者 /usr/sbin/apxs。打开并检查类似如下的行:
my $CFG_CFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LD_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl
my $CFG_CFLAGS_SHLIB = '-fpic -DSHARED_MODULE'; # substituted via Makefile.tmpl my $CFG_LD_SHLIB = 'gcc'; # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = q(-shared); # substituted via Makefile.tmpl
my $CFG_LIBEXECDIR = 'modules'; # substituted via APACI install
my $CFG_LIBEXECDIR = '/usr/lib/apache'; # substituted via APACI install
如果 make时遇到类似这样的问题:
microtime.c: In function `php_if_getrusage': microtime.c:94: storage size of `usg' isn't known microtime.c:97: `RUSAGE_SELF' undeclared (first use in this function) microtime.c:97: (Each undeclared identifier is reported only once microtime.c:97: for each function it appears in.) microtime.c:103: `RUSAGE_CHILDREN' undeclared (first use in this function) make[3]: *** [microtime.lo] Error 1 make[3]: Leaving directory `/home/master/php-4.0.1/ext/standard' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/home/master/php-4.0.1/ext/standard' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/master/php-4.0.1/ext' make: *** [all-recursive] Error 1
你的系统坏了。你需要安装一个符合你的 glibc 的 glibc-devel 包来修复 /usr/include中的文件。这和 PHP 绝对没有任何关系。要证实这一点,试试这个简单的测试:
$ cat >test.c <<X #include <sys/resource.h> X $ gcc -E test.c >/dev/null
首先,我们需要认识到这只是个 警告,而非致命错误。由于这条信息通常是在 make的最后输出的,所以看起来它可能像是一个致命错误,但实际上不是。当然,如果将编译器设置成遇见警告信息时停止,则这也可以算是致命错误。另外值得一提的是,MySQL 的支持是默认打开的。
Note:
自 PHP 4.3.2 起,你将在编译(make)结束后看到下面的文字:
Build complete. (It is safe to ignore warnings about tempnam and tmpnam).
要么在你当前的 PHP 的安装目录查看 config.nice 文件,如果没有,只要运行此脚本:
<?php phpinfo(); ?>
确保你的 GD 库和 PHP 在连接时使用了用同样的支持库(例如 libpng)。
当编译 PHP 时使用非 GNU 的工具会导致问题。确保使用 GNU 工具来确保能够正确编译 PHP。例如,在 Solaris 下面不论使用 SunOS BSD 兼容或者 Solaris 版本的 sed都不行,但是使用 GNU 或者 Sun POSIX (xpg4) 版本的 sed就可以。相关连接: » GNU sed, » GNU flex, » GNU bison。
richard at bpr-s dot de (2012-11-28 21:48:51)
When you have installed PHP5 as a package from your distribution source list, such as yast or apt and want to upgrade the probably out of date PHP5 version make sure:
1. Apache-develope tools are installed so that you have APXS(2)
2. make a clean install which means:
make distclean
./configure --with-apxs2=/usr/sbin/apxs2 and other options
make && make test && make clean install
This will take a while, the make test basically tests your php installation if it passes all the bug reports, as of now about 8600.
Those thre lines will take a while longer! So dont panic, but read the output!
This should ensure, that you have .so files again (because of the APXS and that you have established a relation between the apache and php. Obviously you needed to deinstall the mod_php5 first. I would highly recommend to train this and verify that you have all the required kernel source files and compiler stuff on a virtual machine before doing that on your productive server!
Fabio (2012-02-22 13:47:20)
When building PHP 5.3.x for Apache 2.4.x you may get an error in the apxs query for the MPM_NAME.
This is because the apxs included in Apache 2.4.x doesn't recognize that query anymore.
To resolve this issue one should modify the PHP configure file to use the right MPM module used by Apache.
To know the used MPM you can execute this command: apachectl -t -D DUMP_MODULES | grep mpm
Then, edit the PHP configure file, search for the APXS_MPM variable and force its value to prefork, event or worker according to the value returned by the previous command.
Hope it helps.
-
Fabio
terry at mackintoshweb dot com (2009-09-19 20:43:30)
The configure script of PHP 5.3.0 has some test lines that use expr with the option --, my expr (version 2.0) does not except --. This causes a run of error messages from the shell like:
./configure: line 2xxx: test: =: unary operator expected
expr: syntax error
I used buildconf --force to see if it would fix this.
While it resulted in a quit different file, it still had the lines of code with expr -- in it.
(2007-05-05 06:48:21)
@ anca-phpdoc at anca dot tv:
You can use ./configure --with-libxml-dir=/path_to_xml2-config
chris dot good at NOSPAM dot infor dot com (2006-05-10 00:12:49)
Re Solaris
I was able to compile PHP 5.0.4 under Solaris 2.6 but I had to use gcc to do it. The source is not compatible with the Solaris C preprocessor. I did not have to install any of the gnu utilities (like sed etc) to get it to compile. It clean compiled & linked immediately using gcc 3.3.2.
timothy at imail dot ru (2006-05-02 07:24:10)
Note on PHP5 setup under RedHat 7
Sometimes php5 fails to build with the following message:
[root@www bin]# ./php5
./php5: error while loading shared libraries: unexpected reloc type 0x80
Below is the configure script used:
# PHP5 CLI build, CGI/SAPI disabled
# Created by configure
'./configure' \
'--enable-libxml' \
'--with-mysql=/path_to_mysql' \
'--with-libxml=/path_to_my_libxml' \
'--program-suffix=5' \
'--disable-cgi' \
"$@"
I used the following trick to get round this:
0. If it is not a clean installation, run 'make clean' to get rid of improperly compiled files
1. run ./configure with required options
2. edit makefile:
2.1 find any LDFLAGS or PROGRAM_LDFLAGS definition
2.2 append -lstdc++ to the end of it
3. Run 'make'
4. Run 'make install'
5. Enjoy!!!
anca-phpdoc at anca dot tv (2005-12-08 19:48:54)
For the configure newbies among us:
If you update or reinstall any of the libraries used to compile in a different directory than they started out, you will need to make sure that you update the config.cache file (or re-generate it) so that configure will not look in the wrong place for the information.
On Mac OS X, for example, I updated my libxml using Fink. Fink placed the files in the /sw directory. However, php was still looking for important libxml files (such as xml2-config) in the old directory (/usr/bin/xml2-config). After updating config.cache with the new value of the xml2-config path, I was able to compile correctly.
datemplar at freePotatoes dot fr (2005-10-03 17:15:31)
If the option --with-apsx2=/path/to/apxs seems to have absolutely no effect and if the configure script ignores the Apache 2.x support, try to shutdown your Apache server (/path/to/bin/apachectl stop) and retry.
It worked here.
didier b. (2005-08-07 04:52:31)
I post here because I was unable to find the information on the web.
I hope it will help someone.
Let say you have 2 apache ruuning, on one you want to have disable_functions set and on the other one you don't.
In fact I have (one) solution compiling two differents php modules with differents path to php.ini
using :
--with-config-file-path=/etc/php5 (for the first one)
--with-config-file-path=/etc/php5.nonchroote (for the second one)
for the second one I do not use "make install" but just
"cp .libs/libphp5.so /usr/lib/apache/1.3/libphp5.nonchroote.so"
Then you have to change the
LoadModule php5_module /usr/lib/apache/1.3/libphp5.nonchroote.so in the second httpd.conf
brad at computechnv dot com (2005-04-07 15:07:28)
My problem was actually with mod_dav (which referred me here). Since they took the time to point people here, I thought I'd go ahead and add my two cents worth and expand on the above since it obviously affects PHP as well. I am running Fedora Core 3, Apache 2.0.53, & PHP 5.03. Apache and PHP were built from source.
The first suggestion in section 13 above was close, but not exactly what I needed. jimsteele's suggestion would have worked, but you would have to do it every time you use APXS. What I did was copy these lines:
my $CFG_CFLAGS_SHLIB = '-fpic -DSHARED_MODULE';
my $CFG_LD_SHLIB = 'gcc';
my $CFG_LDFLAGS_SHLIB = q(-shared);
and pasted them in the configuration section of my apxs file. Worked like a champ.
dl927 at torfree dot net (2004-02-11 21:17:18)
Compiling mod_php4 port on a clean freeBSD 4.8 install for Apache2 needed FOR_APACHE2= yes manually inserted into Makefile prior to version check.
dale at botkin dot org (2002-11-04 14:20:06)
If you have customized your Apache to lie about its version number, you may need to edit configure to skip the version number check. Just /APACHE_VERSION in configure to find the instance(s) where configure checks to make sure you have the right combination of --with-apxs or --with_apxs2 and Apache 1.3 or 2.0. Assuming you're smart enough to remember which version of Apache you have, you can just delete or comment out the version check and continue to march.
jimsteele at nospam dot com (2001-10-14 13:43:15)
Defining the right environment variables for my Apache "make" invocation allowed the correct "apxs" file to be generated for me. Your mileage may vary.
cd ../apache_1.3.22
CFLAGS_SHLIB="-fpic -DSHARED_MODULE" \
LD_SHLIB=gcc \
LDFLAGS_MOD_SHLIB="-shared" \
make