前言:
Nginx网站架构实战------01、Nginx介绍及编译安装:传送门
Nginx网站架构实战------02、Nginx信号量:传送门
Nginx网站架构实战------03、nginx虚拟主机配置:传送门
Nginx网站架构实战------04、nginx日志管理:传送门
Nginx网站架构实战------05、nginx定时任务完成日志切割:传送门
Nginx网站架构实战------06、Location详解之精准匹配:传送门
Nginx网站架构实战------07、Location之正则匹配:传送门
Nginx网站架构实战------08、nginx Rewrite语法详解:传送门
Nginx+php的编译 {#nginxphp的编译}
apache一般是把php当做自己的一个模块来启动的。
而nginx这是把http请求变量(如get,user_agent等)转发给php进程,即php独立进程,与nginx进行通信。成为fastcgi运行方式。
因此,为apache所编译的php,是不能用于nginx的。
注意:我们编译的php要有如下功能:链接mysql,gd,ttf,以fpm(fastcgi)方式运行
[sourcecode language="plain"]
[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();
[/sourcecode]
客户端验证
{#客户端验证}
为了为后面的实验做铺垫,把mysql也一并安装上去 {#为了为后面的实验做铺垫把mysql也一并安装上去}
[sourcecode language="plain"]
[root@tiejiang ~]# yum -y install mysql mysql-devel mysql-server
[root@tiejiang ~]# service mysqld start
[/sourcecode]