CentOS 5 下安裝nginx1.05+php5.3+mongodb1.82支援-筆記

來源:互聯網
上載者:User

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";
}

?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.