免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3596 | 回复: 0

在ubuntu9.04上编译安装apache和php [复制链接]

论坛徽章:
0
发表于 2010-01-18 10:42 |显示全部楼层
主机为ubuntu9.04,自带php5.2.10, 32位.
下载apache
wget http://apache.freelamp.com/httpd/httpd-2.2.14.tar.bz2
解压并
./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-MODULE="deflate expires rewrite ssl vhost-alias"
然后
make
停止自带的apache2
sudo /etc/init.d/apache2 stop
运行rcconf,去掉apache2的自启动,安装apache
make install
测试一下
sudo /usr/local/apache2/bin/apachectl start
显示
It works!
表明apache已经安装成功
下载php5.2.12的源码
wget http://cn.php.net/get/php-5.2.12.tar.bz2/from/this/mirror
解压
tar jxvf php-5.2.12.tar.bz2
cd php-5.2.12/
编译php
./configure --prefix=/usr/local/php5.2 --with-apxs2=/usr/local/apache2/bin/apxs --with-bz2 --enable-zip --enable-calendar --
with-mysql --with-pdo-mysql --enable-sqlite-utf8 --with-iconv=/usr/bin/iconv --enable-mbstring --with-curl --enable-exif --
with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr --with-ttf=/usr --with-freetype-
dir=/usr --enable-gd-native-ttf --enable-soap --enable-sockets --with-mcrypt --with-mhash --enable-shmop --with-
mcrypt=/usr/local --with-mhash=/usr/local --without-xpm-dir --with-xmlrpc
先提示
libxml not found
于是
sudo apt-get install libxml2-dev
再提示
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
但ubuntu自带bzip2的,查看php源码中的ext/bz2/config.m4,原来要在参数中的目录、/usr/local、/usr的include中查找bzlib.h,
因为ubuntu9.04似乎没有bzip2-dev的库,所以只有手工下载一个bzip2-1.0.5.tar.gz,解压后
make
sudo make install
现在编译提示
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in /include/curl/
于是
sudo apt-get install curl
结果还是出错,只好下载curl-7.19.3.tar.bz2,解压后编译,然后再编译php,提示
configure: error: libjpeg.(a|so) not found.
那就下载libjpeg,
wget http://www.ijg.org/files/jpegsrc.v8.tar.gz
注意不要下载那个windows版本,即jpegsr8.zip。然后编译安装,现在提示
configure: error: libpng.(a|so) not found.
下载libpng,注意不要下载zip版本,否则./configure时会出现
-bash: ./configure:/bin/sh^M:损坏的解释器: 没有该文件或目录
要下载tar.gz
wget http://downloads.sourceforge.net/project/libpng/01-libpng-master/1.4.0/libpng-1.4.0.tar.gz?use_mirror=nchc
编译安装后,再试,提示
If configure fails try --with-xpm-dir=
configure: error: freetype.h not found.
于是下载并编译安装freetype,再试,提示
checking for iconv support... yes
configure: error: Please reinstall the iconv library.
就再下载iconv并编译安装,再试,提示
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
下载libmcrypt,在configure时提示
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking for C++ compiler default output file name... configure: error: C++ compiler cannot create executables
See `config.log' for more details.
看来是缺g++编译器,
sudo apt-get install build-essential
再重编译安装libmcrypt,再试php,提示
configure: error: Please reinstall libmhash - I cannot find mhash.h
下载mhash并编译安装,再试,提示
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... /tmp/mysql.sock
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
那就在--with-mysql=/opt/mysql5.1 --with-pdo-mysql=/opt/mysql5.1这两处指定一下mysql的地址,最终成了
./configure --prefix=/usr/local/php5.2 --with-apxs2=/usr/local/apache2/bin/apxs --with-bz2 --enable-zip --enable-calendar --
with-mysql=/opt/mysql5.1 --with-pdo-mysql=/opt/mysql5.1 --enable-sqlite-utf8 --with-iconv=/usr/bin/iconv --enable-mbstring -
-with-curl --enable-exif --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr --with-
ttf=/usr --with-freetype-dir=/usr --enable-gd-native-ttf --enable-soap --enable-sockets --with-mcrypt --with-mhash --enable-
shmop --with-mcrypt=/usr/local --with-mhash=/usr/local --without-xpm-dir --with-xmlrpc
现在configure通过了,再来make,最后出错了,
libtool: link: warning: library `/opt/mysql5.1/lib/libmysqlclient_r.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libz.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libz.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libz.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libz.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libmysqlclient_r.la' was moved.
libtool: link: warning: library `/opt/mysql5.1/lib/libz.la' was moved.
ext/gd/libgd/.libs/gd_png.o: In function `php_gd_gdImageCreateFromPngCtx':
/home/my/php5/down/php-5.2.12/ext/gd/libgd/gd_png.c:142: undefined reference to `png_check_sig'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1
经查,mysql部分的warning可能没啥影响,详见
http://bbs3.chinaunix.net/thread-1469391-1-1.html
因为我的libz.la中为
# The name that we can dlopen(3).
dlname=''
# Names of this library.
library_names=''
# The name of the static archive.
old_library='libz.a'
那就暂不管吧。后面的看起来象是gd编译出错,先下载gd试试,
wget http://www.libgd.org/releases/gd-2.0.35.tar.bz2
在对gd进行make时也出错了,
gcc -g -O2 -o .libs/annotate annotate.o /usr/local/lib/libiconv.so -Wl,-rpath -Wl,/usr/local/lib  -L/usr/local/lib
./.libs/libgd.so /usr/local/lib/libjpeg.so /usr/local/lib/libfreetype.so /usr/local/lib/libpng14.so -lz -lm
./.libs/libgd.so: undefined reference to `png_check_sig'
collect2: ld returned 1 exit status
make[2]: *** [annotate] 错误 1
make[2]:正在离开目录 `/home/my/php5/down/gd-2.0.35'
make[1]: *** [all-recursive] 错误 1
make[1]:正在离开目录 `/home/my/php5/down/gd-2.0.35'
make: *** [all] 错误 2
于是换php版本到php-5.2.8,结果在php5.2.8中make也是这样错,不知是不是xpm的问题,想编译xpm,竟然make不了,也没configure,那apt
试试
sudo aptitude install libgd2-xpm libgd2-xpm-dev
会提示装很多东西,有些刚才都编译安装了的,
下列“新”软件包将被安装。
  libexpat1-dev{a} libfontconfig1-dev{a} libfreetype6-dev{a} libgd2-xpm-dev libjpeg62-dev{a} libpng12-dev{a}
  libpthread-stubs0{a} libpthread-stubs0-dev{a} libx11-dev{a} libxau-dev{a} libxcb1-dev{a} libxdmcp-dev{a} libxpm-dev{a}
  x11proto-core-dev{a} x11proto-input-dev{a} x11proto-kb-dev{a} xtrans-dev{a}
下列软件包将被升级:
  libgd2-xpm
1 个软件包被升级,新安装 17 个, 0 个将被删除, 同时 186 个将不升级。
需要获取 4,713kB 的存档。 解包后将要使用 14.6MB。
您要继续吗?[Y/n/?]
安装后再试看来还是不行。找不到原因,只有换回原来用的libpng-1.2.35,编译安装,再试php-5.2.8的make,这下没错误了,当然那个mysql的
warning还在,完成后提示用make test检查,检查的结果为:
EXPECTED FAILED TEST SUMMARY
---------------------------------------------------------------------
SPL: ArrayObject::__construct basic usage with ArrayObject::ARRAY_AS_PROPS.
[ext/spl/tests/arrayObject___construct_basic4.phpt]
SPL: ArrayObject::__construct basic usage with ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS.
[ext/spl/tests/arrayObject___construct_basic5.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
[ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]
SPL: ArrayObject::setFlags basic usage with ArrayObject::ARRAY_AS_PROPS. [ext/spl/tests/arrayObject_setFlags_basic1.phpt]
=====================================================================
You may have found a problem in PHP.
We would like to send this report automatically to the
PHP QA team, to give us a better understanding of how
the test cases are doing. If you don't want to send it
immediately, you can choose "s" to save the report to
a file that you can send us later.
Do you want to send this report now? [Yns]:
不知道这个有什么影响,再来编译一下php-5.2.12试试,也通过,但make test后的结果为
EXPECTED FAILED TEST SUMMARY
---------------------------------------------------------------------
output buffering - fatalism [tests/output/ob_011.phpt]
ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush() [tests/output/ob_start_basic_unerasable_005.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
[ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]
=====================================================================
You may have found a problem in PHP.
We would like to send this report automatically to the
PHP QA team, to give us a better understanding of how
the test cases are doing. If you don't want to send it
immediately, you can choose "s" to save the report to
a file that you can send us later.
Do you want to send this report now? [Yns]:
怎么看起来都有错,那只有安好再测试一下吧,进php-5.2.12,然后
sudo make install
Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' libphp5.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp libphp5.la /usr/local/apache2/modules/
cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so
cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /home/my/php5/down/php-5.2.12/libs'
chmod 755 /usr/local/apache2/modules/libphp5.so
[activating module `php5' in /usr/local/apache2/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php5.2/bin/
Installing PHP CLI man page:      /usr/local/php5.2/man/man1/
Installing build environment:     /usr/local/php5.2/lib/php/build/
Installing header files:          /usr/local/php5.2/include/php/
Installing helper programs:       /usr/local/php5.2/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php5.2/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php5.2/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.3
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Structures_Graph- installed: 1.0.2
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.0
Wrote PEAR system config file at: /usr/local/php5.2/etc/pear.conf
You may want to add: /usr/local/php5.2/lib/php to your php.ini include_path
Installing PDO headers:          /usr/local/php5.2/include/php/ext/pdo/
注意到其中提示要运行
libtool --finish /home/my/php5/down/php-5.2.12/libs
然后再运行apache,
sudo /usr/local/apache2/bin/apachectl start
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into
server: /usr/local/apache2/modules/libphp5.so: undefined symbol: png_check_sig
看来那个png_check_sig的问题还是没解决,现在进libpng源码目录,make uninstall,再进/usr/lib和/usr/local/lib,把所有libpng*全删除了,
再来编译一次,可能还得装gd吧.
装libpng-1.4.0算了,先make clean,然后再make,make install,
再编译安装gd-2.0.35,没加参数,然后进php-5.2.12,先configure,没有任何错误提示,再make,最后还是png_check_sig错误.
再分析出错提示,难道是因为缺少ext/gd/.libs/gd_png.o这个文件?进这个目录看果然没有此文件,是编译时没生成?为什么?幸好上一个服务器
编译php-5.2.8成功的文件还在,进这个目录看,也只有gd.o和gdttf.o两个文件.
再上网狂搜索,
http://aspn.activestate.com/ASPN/Mail/Message/php-dev/3803631
这儿有眉目了,看来是php的一个bug,libpng-1.4.0源码中的libpng-1.4.0.txt有说明,已经取消了png_check_sig这个函数,改用png_sig_cmp代
替.自从libpng-0.90就已经反对使用png_check_sig函数了.这个帖子中采用修改php源码的方法,编辑ext/gd/libgd/gd_png.c,将
if (!png_check_sig (sig, 8)) { /* bad signature */
换成
if (png_sig_cmp (sig, 0, 8)) { /* bad signature */
但我不知道其他哪些地方有没有这个函数,所以我还是用libpng-1.2.35吧,看libpng-1.2.35.txt,就没有提png_check_sig的事.
编译安装libpng-1.2.35后,php-5.2.12的make通过了,那再来make test一下,还是那个ob_start的错误
output buffering - fatalism [tests/output/ob_011.phpt]
ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush() [tests/output/ob_start_basic_unerasable_005.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
[ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]
不管了,安好再说./usr/local/apache2/conf/httpd.conf中已经被自动加入
LoadModule php5_module        modules/libphp5.so
我们还要手工加入
AddType application/x-httpd-php .php .phtml
然后在/usr/local/apache2/htdocs中新建一个php文件,内容为
在浏览器中输入地址,显示php的信息,好,成功了.
现在完成收尾工作,在apache2目录先备份原来的conf
sudo mv conf conf.original
再将原来在/etc目录下的apache设置文件复制过来
sudo cp -R /etc/apache2 conf
再进conf,把原来的apache2.conf复制为httpd.conf,并修改其中的包含路径,再启动apache,会有不少错误提示,类似
/usr/local/apache2/conf/httpd.conf: Syntax error on line 1 of /usr/local/apache2/conf/mods-enabled/auth_basic.load: module
auth_basic_module is built-in and can't be loaded
看来新版本的apache2已经包含了不少内建模块,那就不停地删除吧,要删除mods-enabled下的
alias.load,auth_basic.load,authn_file.load,authz_default.load,authz_default.load,authz_groupfile.load,authz_host.load,authz_u
ser.load,autoindex.load,dir.load,env.load,mime.load,negotiation.load,setenvif.load,status.load
再启动apache2,提示
[Sun Jan 17 00:02:04 2010] [crit] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  
You need to recompile PHP.
Pre-configuration failed
竟然不能用worker模式,但开始为什么能行?查看mods-enabled下有php5.load,内容为
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
原来是在读取另外的php5模块,那就删除php5.load,这下再启动,提示
httpd: bad user name ${APACHE_RUN_USER}
再查看bin/apachectl脚本,有
if test -f /usr/local/apache2/bin/envvars; then
这样一句,看来和ubuntu自带的不同,那就在/usr/local/apache2/bin/envvars中加入
export APACHE_RUN_USER=daemon
export APACHE_RUN_GROUP=daemon
export APACHE_PID_FILE=/var/run/apache2.pid
最后一句是怕出错,也许没影响.再启动提示
Syntax error on line 216 of /usr/local/apache2/conf/httpd.conf:
Unrecognized LogFormat directive %O
上网搜索,好象是因为没有启用mod_logio,所以不能在日志中用%O,那就把httpd.conf中日志的%O去掉,再启动,没错误提示了,但访问php,竟然变
成下载了,文件类型为application/x-httpd-php.原来是不该去掉php5.load,只要把其中的so改成modules/libphp5.so就行了.现在显示正常了.
再来测试php的make test时的错误,先测试ob_start和ob_flush,
结果!!!显示在字符串中间,看起来没问题.
但是那个php数组的下标类似于大整数时变负数的问题依然存在.
输出
array ( 222 => 'small', -2072745074 => 'OS:Linux,PHP:5.2.12', '222222222222222222222222222222222222' => 'big!', )
怀疑是因为worker模式问题,把apache重新编译,去掉--with-mpm=worker,然后再编译php-5.2.12,也不对.
怀疑是没有php.ini的问题,把源码下的php.ini-dist复制到/usr/local/php5.2/lib为php.ini,但还是老样子.
怀疑是php版本高了,但是看有人在freebsd上用的是5.2.11都正确.不管怎么说,先编译5.2.8,再试,终于正确了.
array ( 222 => 'small', '2222222222' => 'OS:Linux,PHP:5.2.8', '222222222222222222222222222222222222' => 'big!', )
这可能是php的bug吧.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4891/showart_2151813.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP