09-编译PHP并与Nginx整合

Nginx+Php的编译

apache一般是把php当做自己的一个模块来启动的。
而nginx这是把http请求变量(如get,user_agent等)转发给php进程,即php独立进程,与nginx进行通信。成为fastcgi运行方式。
因此,为apache所编译的php,是不能用于nginx的。
注意:我们编译的php要有如下功能:链接mysql,gd,ttf,以fpm(fastcgi)方式运行
php是嵌入式嵌入apache当做它的小功能块。nginx和php的关系是平等的。信息原封不动地给9000端口,让9000端口去处理。

[root@tiejiang ~]# cd /usr/local/src/
[root@tiejiang src]# tar -zxvf php-5.4.5.tar.gz
[root@tiejiang php-5.4.5]# yum -y install libxml2 libxml2-devel libpng libpng-devel
[root@tiejiang php-5.4.5]# ./configure  --prefix=/usr/local/fastphp --with-mysql=mysqlnd --enable-mysqlnd --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --enable-fpm
[root@tiejiang php-5.4.5]# make && make install
[root@tiejiang php-5.4.5]# cd /usr/local/fastphp/
[root@tiejiang fastphp]# ls
    bin  etc  include  lib  php  sbin  var
[root@tiejiang fastphp]# cp /usr/local/src/php-5.4.5/php.ini-development ./lib/php.ini
[root@tiejiang fastphp]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@tiejiang fastphp]# ./sbin/php-fpm
[root@tiejiang fastphp]# ps aux | grep php
    root     128637  0.0  0.3 139684  3032 ?        Ss   09:48   0:00 php-fpm: master process (/usr/local/fastphp/etc/php-fpm.conf)
    nobody   128638  0.0  0.3 139684  2660 ?        S    09:48   0:00 php-fpm: pool www
    nobody   128639  0.0  0.3 139684  2660 ?        S    09:48   0:00 php-fpm: pool www
    root     128643  0.0  0.1 103260   848 pts/2    S+   09:49   0:00 grep php
[root@tiejiang nginx]# vim conf/nginx.conf
        #用location匹配,碰到php结尾的文件
        location ~ \.php$ {
        #把根目录定位到 html
            root           html;
        #全部交给fastcgi_pass来处理,把请求上下文转交给9000端口PHP进程,  
            fastcgi_pass   127.0.0.1:9000;  
        #拿谁来做默认首页
            fastcgi_index  index.php;
        #为了告诉php进程,我想运行哪个php页面,配置不好会提示502报错
            fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }

[root@tiejiang nginx]# cat html/test.php 
    <?php
    phpinfo();

Mysql安装

[root@tiejiang ~]# yum -y install mysql mysql-devel mysql-server
[root@tiejiang ~]# service mysqld start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值