apache 编译支持php_apache编译安装,配置支持fastcgi,php-fpm

说明:

系统本身为LNMP编译安装,后来需要使用httpd,因为不想再重新编译一遍php,php通过php-fpm管理,因此希望新编译安装的httpd能直接调用原来的php。

思路主要是:想httpd应该是碰到htm,html直接处理;碰到php等,则是通过在httpd.conf中LoadModule php处理模块,调用php-fpm来处理php请求。因此,应该是不需要重新编译php,php-fpm才对。

实现:

1.编译安装httpd

cd/usr/local/src

wget http://www.apache.org/dist/httpd/httpd-2.4.4.tar.gztar zxvf httpd-2.4.4.tar.gz

cd httpd-2.4.4./configure--prefix=/usr/local/apache--enable-so--enable-mods-shared=all--enable-cgi--enable-rewrite--enable-deflate--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util--with-mpm=worker//--enable-so模块是httpd的apxs工具,该工具实现功能类似php的phpize,是编译和安装扩展模块的工具;--enable-mods-shared=most --with-mpm=worker作用给忘了make&&make install

若安装过程出现 “APACHE 安装出错 configure: error: Cannot use an external APR with the bundled APR-util ;configure: error: Cannot use an external APR with the bundled APR-util ”请参考附录5:编译安装apr,apr-devel

2.mod_fastcgi的安装,这个是httpd调用fastcgi处理php的模块

# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz# tar -zxvf mod_fastcgi-2.4.6.tar.gz# cd mod_fastcgi-2.4.6# wget http://leeon.me/upload/other/byte-compile-against-apache24.diff# patch -p1 < byte-compile-against-apache24.diff //apache2.4下安装mod_fastcgi 2.4.6 ,需要打补丁# cp Makefile.AP2 Makefile# vim Makefile 将Makefile中的路径改成你的apache的安装路径# make && make install //安装成功后,会自动把mod_fastcgi.so复制到/usr/local/apache/modules目录

3.修改http文件

# vim /usr/local/apache/conf/httpd.confLoadModuleactions_module modules/mod_actions.so//删除这行前面的#注释LoadModulefastcgi_module modules/mod_fastcgi.so//添加这行,mod_fastcgi.so为上一步mod_fastcgi生成的

4.httpd调用php有4种模式:模块模式;CGI模式;fastCgi模式,apche内置进程管理器;fastCgi模式,php-fpm进程管理器。我这里就试了2种:模块模式;fastCgi模式,php-fpm进程管理器。

a.模块模式,这种模式最简单,在httpd.conf中增加LoadModule php5_module modules/libphp5.so,然后在VirtualHost添加以下内容:

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot /www/test

ServerName www.nobody.com

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

AddType application/x-httpd-php .php

AddType applicaiton/x-httpd-php-source .phps//也可以将AddType按模块方式载入,就不需要上面两行AddTypeAddType application/x-httpd-php .php

AddType applicaiton/x-httpd-php-source .phps

b.fastcgi模式,php-fpm进程管理器

首先添加fastcgi模块到httpd.conf配置文件:LoadModule fastcgi_module modules/mod_fastcgi.so。这种模式注不注释LoadModule php5_module modules/libphp5.so这行貌似没什么关系。虚拟主机配置为以下:

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot /www/test

ServerName www.nobody.com

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

ScriptAlias /cgi-bin/ "/usr/local/php/sbin/" //这里要加个虚拟目录指定php,直接使用会出现权限不足

FastCgiExternalServer /usr/local/php/sbin/php-fpm -host 127.0.0.1:9000 //这里因为是调用php-fpm管理fastcgi,因为这里是/usr/local/php/sbin/php-fpm,而不是什么cgi-bin

AddType application/x-httpd-php .php

AddHandler php-fastcgi .php

Action php-fastcgi /cgi-bin/php-fpm

5.httpd的启动,重启等

# /usr/local/httpd/bin/apachectl start|restart

附录:

附录1.undefined reference to `libiconv

一开始以为是libiconv的问题,重装了好几次还是一样,最后终于找着办法了

把–with-iconv-dir=/usr/local 改为 –with-iconv-dir=/usr/local/lib

附录2.手动编译PHP安装时遇到如下错误undefined reference to `libiconv_open’,undefined reference to `libiconv_close’等

/usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open’ /usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv’ /usr/local/src/php-5.3.10/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close’ collect2: ld returned 1 exit status make: *** [sapi/fpm/php-fpm] 错误

表面看,是libiconv安装问题,重装libiconv之后问题依旧,网上看有人舍弃libiconv,使用 –without-iconv,我觉的不可取,这样是回避问题。 找了n久,终于找到bug所在: 在执行完 ./configure … 之后,修改下 Makefile,找到其中的

EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lldap -llber -lfreetype -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt

在最后面添加 -liconv ,修改后如下

EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lldap -llber -lfreetype -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -liconv

附录3.关于php编译时SAPI错误

近日在ubuntu11.04server版上编译php的时候出现了错误,错误截图如下:

You’ve configured multiple SAPIs to be build.You can build only one SAPI module and CLI binary at the same time.(你已经配置了多个SAPIs,你只可以建立一个SAPI模块和一个CLI binary。)

导致的原因是我的配置参数中同时使用了–enable-fpm 与–with-apxs2= ,因此编译的时候出错了,去掉其中的任意一个参数编译成功。

附录4.mod_fastcgi.c:: error: request for member ‘log’ in something not a structure or union

mod_fastcgi.c:2867:9: 警告: 格式字符串不是一个字面字符串而且没有待格式化的实参

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘log’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘log’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘connection’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘connection’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘server’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘log’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘log’

mod_fastcgi.c:2881:5: 错误: 在非结构或联合中请求成员‘connection’

我的问题已经解决,apache2.4 下安装mod_fastcgi 2.4.6 ,需要打补丁,具体方法如下:

# wget http://leeon.me/upload/other/byte-compile-against-apache24.diff //下载补丁文件

# cd /root/mod_fastcgi-2.4.6 并上传本文中提供的diff patch文件到此目录

# patch -p1 < byte-compile-against-apache24.diff 打补丁即可

最后make && make install 编译mod_fastcgi,然后在apache的conf文件中加入module即可。

附录5.APACHE 安装出错 configure: error: Cannot use an external APR with the bundled APR-util

configure: error: Cannot use an external APR with the bundled APR-util

根据错误信息进行解决,只需要安装apr和apr-util即可,http://apr.apache.org上有这些源码包自己编译安装

# tar xzvf apr-1.2.9.tar.gz# cd apr-1.2.9# ./configure --prefix=/usr/local/apr# make# make install# tar xzvf apr-util-1.2.8.tar.gz# cd apr-util-1.2.8# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr# make# make install

接下来安装apache,安装将不再出错

附录6.make: 警告:检测到时钟错误。您的创建可能是不完整的

如果上一次编译时为20071001,你把系统时间改成20070901后再编译就会报这样的错误.

解决:把时间改了或运行下来命令再make

# find . -type f -exec touch {} ;

附录7.重新编译安装php,在考虑删除附录7

重新编译是因为我之前编译使用–enable-fpm 而不是–with-apxs2参数。–with-apxs2这个参数的作用是把php的解释模块编译成libphp5.so文件添加到apache的modules中。

后面有看到说:如果我们不想用模块模式的话,在httpd.conf加入:LoadModule php5_module modules/libphp5.so。但不编译,哪里有libphp5.so,好奇。而且–witch-apx2不像其它ext扩展包,能使用phpize来添加,估计是内部参数。–enable-fpm –with-apxs2 两者的区别也还没去查。

# cd /usr/local/src/php-5.3.6# make clean# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local/lib --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-apxs2=/usr/local/httpd/bin/apxs# vim Makefile //在Makefile EXTRA_LIBS最后添加-liconv,不然会出现 undefined reference to `libiconv_open' undefined reference to `libiconv_close'等libiconv问题。# make && make install

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值