部署PHP

昨天下午我自己试着部署了一下apache+php。自己做一遍总会碰到各式的问题的,这边记录一下。这是我们组的实习生开发的一个小工具,需要serve query,需要发http request到别的节点获取信息,需要访问oracle数据库。

需要安装的模块:

  1. apache http server。
  2. php。
  3. php pecl_http 扩展用于支持向别的http server发送http request并获取结果。
  4. php oci8 扩展,用于访问oracle数据库。

由于我们的solaris dev机器是共享的,所以我不想安装在/usr/local下,上面的4个模块全部重新编译部署。

Apache Http Server:
http://httpd.apache.org/ 下载源代码zip包。
-bash-3.00$ wget http://www.devlib.org/apache/httpd/httpd-2.2.10.tar.gz
-bash-3.00$ gzip -d http-2.2.10.tar.gz
-bash-3.00$ tar -xvf http-2.2.10.tar.gz
-bash-3.00$ cd http-2.2.10
这里可以看到一个INSTALL文件,里面有详细的安装部署方法

-bash-3.00$ ./configure –help   查看所有的configure选项,configure的作用之一就是更具你的机器,生成具体的makefile。
-bash-3.00$ ./configure –prefix=/home/arrowpig/install/apache –enable-module=so
如果没有–prefix,待会安装的时候就会部署到/usr/local下面,使用–prefix可以覆盖默认的安装位置,–enable-module=so的意思是我希望apache能够dynamic load配置文件中所需要的模块(支持Dynamic Shared Object )。

-bash-3.00$ make  开始编译apache
-bash-3.00$ make install 将apache部署到–prefix所对应的目录
-bash-3.00$ cd /home/arrowpig/install/apache/conf  该目录下的httpd.conf就是apache的配置文件,我们可以做一个备份
-bash-3.00$ cd /home/arrowpig/install/apache/bin
-bash-3.00$ ./apachectl start  启动apache http server

PHP:
http://www.php.net/ 下载源代码zip包。步骤和安装apache http server一样的。解压,./configure,make, make install。http://www.php.net/manual/en/ 上有详细的文档。

-bash-3.00$ ./configure –prefix=/home/arrowpig/install/php –with-apxs2=/home/arrowpig/install/apache/bin/apxs
–with-apxs2 告诉php使用apache的apxs工具来build shared Apache 2.0 handler module。

不幸的是,运行./configure后,我得到了这个错误:
"configure: error: libxml2 version 2.6.11 or greater required."

于是我去网上下了一个libxml2,自己编译安装到arrowpig/install/libxml2目录下,并设置了环境变量:
export PATH=/home/arrowpig/install/libxml2/bin:$PATH
export LD_LIBRARY_PATH=/home/arrowpig/install/libxml2/lib:$LD_LIBRARY_PATH
但是并没有起到作用,看来php的configure脚本并不是依靠LD_LIBRARY_PATH来检查libxml2的版本的。

于是我只好打开configure脚本看看:
for i in $PHP_LIBXML_DIR /usr/local /usr; do
    if test -x "$i/bin/xml2-config"; then
      ac_cv_php_xml2_config_path="$i/bin/xml2-config"
      break
    fi
done

可见,在没有设置$PHP_LIBXML_DIR的时候,脚本只到/usr/local和/usr下寻找 xm2-config,并使用xm2-config得到版本号。所以我把./configure 参数修改成:
./configure –prefix=/home/arrowpig/install/php –with-apxs2=/home/arrowpig/install/apache/bin/apxs
–with-apxs2 –with-libxml-dir= /home/arrowpig/install/libxml2/
这样就可以了,然后运行make, make install。 我们可以检查,安装好以后,在apache的modules目录下:

-bash-3.00$ pwd
/home/arrowpig/install/apache/modules
-bash-3.00$ ls
httpd.exp   libphp5.so

-bash-3.00$ cp /home/arrowpig/download/php-5.2.6/php.ini-dist /home/arrowpig/install/php/lib/php.ini
php.ini就是php的配置文件。

最后,在apache 的httpd.conf中加入下面的内容:

LoadModule php5_module modules/libphp5.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>

然后重新启动apache:
-bash-3.00$ ./apachectl restart

验证PHP已经被正确安装:
我们可以在apache的DocumentRoot目录下面,放置这样一个文件phpinfo.php

<?php
phpinfo();
?>

访问   http://arrowpig.dev.ebay.com:10000/phpinfo.php 我们就可以看到关于当前php的所有配置信息。

PHP pecl_http: 在线文档
在我们build php的时候,就自动安装了pear, pear是管理php extension的一个工具。在/home/arrowpig/install/php/bin
-bash-3.00$ ls
package.xml   package2.xml   pear    peardev   pecl     php   php-config    phpize

-bash-3.00$ ./pecl help 可以查看命令选项
-bash-3.00$ ./pecl install pecl_http   安装pecl_http扩展

注意pecl会提示我们在安装pecl_http的时候的选项,不幸的是pecl的提示有点confusing…

1. whether to enable cURL HTTP requests; specify libcurl directory : yes

1-1, ‘all’, ‘abort’, or Enter to continue:

按回车就是接受默认选项,但是我还没有安装libcurl。我实际需要做的是先安装libcurl,然后在这里输入本机的libcurl的安装目录。输入’no’ 并不会修改设置,要修改配置,必须先输入’all’,然后输入修改的配置,回车确认,pecl会要求你再确认一次,这个时候输入Enter才真正生效:

1. whether to enable cURL HTTP requests; specify libcurl directory : yes

1-1, ‘all’, ‘abort’, or Enter to continue: all
whether to enable cURL HTTP requests; specify libcurl directory [yes] : /home/arrowpig/install/curl
1. whether to enable cURL HTTP requests; specify libcurl directory : /home/arrowpig/install/curl

1-1, ‘all’, ‘abort’, or Enter to continue: (按回车确认上面的设置)

1. whether to enable support for gzencoded/deflated message bodies; specify zlib directory : yes

1-1, ‘all’, ‘abort’, or Enter to continue: all
whether to enable support for gzencoded/deflated message bodies; specify zlib directory [yes] : no
1. whether to enable support for gzencoded/deflated message bodies; specify zlib directory : no

1-1, ‘all’, ‘abort’, or Enter to continue: (按回车确认上面的设置)

当一起就绪后,在php.ini中添加:
extension=http.so   

然后重新启动apache就可以了,访问phpinfo.php我们可以看到http模块已经被加载。

PHP OCI8 扩展
安装方法和pecl_http一模一样。
-bash-3.00$ ./pecl install oci8

这样就完成了这个小工具所需要的PHP的整个环境配置。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值