nginx+php配置简单介绍

来源:互联网 发布:淘宝宝贝卖点怎么写 编辑:程序博客网 时间:2024/06/02 01:59

1.nginx安装

下载nginx源码


。/configre

make  

make test 

make install

就完成安装了 缺少什么包就 yum  install  xx

[root@localhost nginx_nocomment]# ./configure --help


  --help                             print this message


  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-pa


set build directory --with-rtsig_module enable rtsig module --with-select_module enable select module --without-select_module disable select module --with-poll_module enable poll module --without-poll_module disable poll module
以上的这些选项都是configure是可以选择的具体是干什么请看选项后面的解释:
--prefix=PATH                      set installation prefix
例如这个就是指定安装的目录
对于这些选项的详解如果有兴趣请看 《深入理解nginx模块开发与架构解析》陶辉著 12页
5.安装源码安装php我安装的是:http://php.net/  
PHP 5.4.14 and PHP 5.3.24 released!


6.下载玩源码后:
[tbin@localhost lnmp]$ cd php-5.4.14
[tbin@localhost php-5.4.14]$ ./configure  --prefix=/usr/local/php  --enable-fpm
[tbin@localhost php-5.4.14]$ make
[tbin@localhost php-5.4.14]$ make test
[tbin@localhost php-5.4.14]$ make install
其中。/configure后面的  --enable-fpm是开启fpm这选项用于解析php文件
在我安装的过程出出现了 “not find libxml2”
命令安装:yum search libxml2 
                : yum install libxml  libxml2-devel
然后重复上的命令就可以安装完成
7.安装问成后php的配置
我的默认安装路径是  /usr/local/php
配置如下:
[tbin@localhost php-5.4.14]$ cp -a php.ini-production /usr/local/php/lib/php.ini
[tbin@localhost php-5.4.14]$ cp -a php.ini-production /usr/local/php/etc/php.ini
以上的两个命令是将下载后解压好的php-5.4.14中的  php.init-production 文件拷贝到  相应的目录中 php.ini-production 文件是php全局的配置文件
以上动作完成以后
[tbin@localhost etc]$ cd /usr/local/php/etc/
将该目录下的  php-fpm.conf-deauful文件该名为  php-fpm.conf 
[tbin@localhost etc]$ ls
pear.conf  php-fpm.conf  php.ini
ls 后会看到以上文件 此时你就可以启动 php的文件解释进程了
[tbin@localhost etc]$ /usr/local/php/sbin/php-fpm 
[root@localhost conf]# ps -ef | grep php
root     31512     1  0 12:34 ?        00:00:01 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody   31513 31512  0 12:34 ?        00:00:00 php-fpm: pool www          
nobody   31514 31512  0 12:34 ?        00:00:00 php-fpm: pool www          
root     32512 31195  0 16:48 pts/1    00:00:00 grep php
这就证明你已经成功启动php-fpm 进程了。
php的安装到此以经完成了。下面就是就是和nginx的链接了。通过nginx来解析php文件


8.nginx配置文件  在/usr/local/nginx/conf  目录中
此时启动nginx 


看看你的nginx启动了没有,我开启了两个worker进程。
一下是我的nginx.conf 文件的配置
user  nobody;
worker_processes  2;               //启动的worker进程数目 最好和cpu核数相当


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


#pid        logs/nginx.pid;




events {
    worker_connections  1024;         // worker进程最大处理的连接数
}




http {
    include       mime.types;
    default_type  application/octet-stream;


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;


    server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   html;             //表示接到请求以后首相会从 /html目录下访问文件。
            index  index.html index.htm index.php;
        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
location ~ \.php$ {
            proxy_pass   http://127.0.0.1:9000;  //需要指定端口 如果不指定 默认的是 80端口
        }


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;
        }


此时只要你在  /usr/local/nginx/html  目录下创建一个XXX.php  文件就可以通过浏览器可以看到了。
以上就是简单的过程。

原创粉丝点击