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