Nginx+PHP(FastCGI)高性能服务器

Nginx+FastCGI安装配置:

yum install pcre-devel pcre –y

#下载Nginx源码包

cd /usr/src

wget -c http://nginx.org/download/nginx-1.6.2.tar.gz 

#解压Nginx源码包

tar -xzf nginx-1.6.2.tar.gz

#预编译Nginx

useradd www ;./configure --user=www --group=www --prefix=/usr/local/nginx --with-

http_stub_status_module --with-http_ssl_module

#.configure预编译成功后,执行make命令进行编译

make

#make执行成功后,执行make install 正式安装

make install

#自此Nginx安装完毕

/usr/local/nginx/sbin/nginx  -t  检查nginx配置文件是否正确,返回OK即正确。

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost ~]#

然后启动nginx,/usr/local/nginx/sbin/nginx 回车即可。查看进程是否已启动:

[root@localhost ~]# ps -ef |grep nginx

nobody    5381 30285  0 May16 ?        00:04:31 nginx: worker process         

root     30285     1  0  2014 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

root     32260 32220  0 12:34 pts/0    00:00:00 grep nginx

[root@localhost ~]#

1) 下载安装并编译PHP

wget  http://museum.php.net/php5/php-5.3.10.tar.gz

yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql mysql-devel(一般数据库是分开的)

2) 进入php目录进行编译安装:

cd php-5.3.10

./configure --prefix=/usr/local/php5  --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysql=/usr/bin/mysql --with-mysqli=/usr/bin/mysql_config

(这里数据库要是源码安装 编译路径要改  例外mysql在别的机器这里就--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd)

make && make install

cp php.ini-development /usr/local/php5/lib/php.ini

cp /usr/local/php5/etc/php-fpm.conf.default

/usr/local/php5/etc/php-fpm.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

3) Ninx配置文件设置conf/nginx.conf:

server {    

 server_name www.jfedu.net jfedu.net;  

  location / {  

 index index.html index.php;  

 root /usr/local/nginx/html;  

 }  

 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;  

        }  

}

 

 

 

然后我们要修改php.ini 的时间  

 

下面我们就要启动PHP-FPM

#/usr/local/php5/sbin/php-fpm  我这里用的是5.6的  一般这里启动不会报错的)

 

在启动PHP-FPM时会报上面这个错误,原因是PHP-FPM自己不知道以那个用户和组运行PHP,所以我们要修改一个文件,把文件中的注释去掉即可(打开文件把红色部分删除),然后PHP-FPM会以nobody用户和组去运行PHP。

#vi /usr/local/php5/etc/php-fpm.conf

 

#/usr/local/php5/sbin/php-fpm 

 

 

4) 测试Nginx+PHP整合结果

cat >> /usr/local/nginx/html/index.php << EOF

<?php phpinfo(); ?>

EOF

 

猜你喜欢

转载自www.cnblogs.com/zhangan/p/10880866.html