CentOS 5 下安装nginx1.05+php5.3+mongodb1.82支持-笔记

1. 安装nginx

(1) 下载nginx http://nginx.org/download/nginx-1.0.5.tar.gz

(2) 解压 tar -zxvf nginx-1.0.5.tar.gz

(3)编译  ./configure --with-http_stub_status_module

会报错,未找到pcre,需要下载pcre ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

注意,需要用root来configure, make , make install

然后安装pcre

有可能报 libtool: compile: unrecognized option `-DHAVE_CONFIG_H'

解决方法:  yum install gcc-c++

再次编译nginx

有可能会报  ./configure: error: the HTTP gzip module requires the zlib library.

解决方法:yum install -y zlib-devel

make   

make install

(4)至此,nginx已安装完成,安装目录在/usr/local/nginx 下

2. 安装php5

(1)下载php  http://www.php.net/get/php-5.3.6.tar.gz/from/cn.php.net/mirror

(2) 解压 tar -zxvf php-5.3.6.tar.gz

(3)编译  ./configure --enable-fpm

会报 libxml2 未找到,安装libxml2  ¥ yum install libxml2 libxml2-devel

继续编译 ./configure --prefix=/usr/local/php  --enable-fpm

(4)make   make install

(5)默认安装目录如下,有些乱,所以编译时最好加上   ./configure --prefix=/usr/local/php  --enable-fpm

Installing PHP SAPI module:       fpm
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/man/man1/
Installing PHP FPM binary:        /usr/local/sbin/
Installing PHP FPM config:        /usr/local/etc/
Installing PHP FPM man page:      /usr/local/man/man8/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.2
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/home/admin/php-5.3.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar
Installing PDO headers:          /usr/local/include/php/ext/pdo/

----------------------------------------------------------------

(5)最后拷贝配置文件  

cp php.ini-development /usr/local/lib/php.ini    

or

cp php.ini-production /usr/local/php/lib/php.ini

(6) mv /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

修改 php-fpm.conf,把 pm.start_servers,pm.min_spare_servers,pm.max_spare_servers,pm.max_requests 打开。

(7)启动fast_cgi管理器, /usr/local/sbin/php-fpm

3.  配置 nginx + php 整合

(1)打开 nginx.conf, 设置

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

(2)启动 nginx ,/usr/local/nginx/sbin/nginx

(3)设置开机启动

echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local 

echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local 

4.  安装mongodb驱动

cd  /usr/local/php/bin

 ./pecl install mongo

最后在php.ini 加入 "extension=mongo.so" 

5. mongodb的测试程序

<?php

// connect
$m = new Mongo();

// select a database
$db $m->comedy;

// select a collection (analogous to a relational database's table)
$collection $db->cartoons;

// add a record
$obj = array( "title" => "Calvin and Hobbes""author" => "Bill Watterson" );
$collection->insert($obj);

// add another record, with a different "shape"
$obj = array( "title" => "XKCD""online" => true );
$collection->insert($obj);

// find everything in the collection
$cursor $collection->find();

// iterate through the results
foreach ($cursor as $obj) {
    echo 
$obj["title"] . "\n";
}

?>



你可能感兴趣的:(mongodb,PHP,nginx,centos,include)