Nginx + PHP web 平台
------------------安装 Nginx-------------------
安装编译工具与依赖环境
# yum install gcc gcc-c++ make pcre-devel openssl-devel zlib-devel -y
# useradd nginx //创建Nginx 用户
# tar -xvf nginx-1.6.2.tar.gz //解压 nginx 源码包
# cd nginx-1.6.2
# ./configure \ //配置 nginx 编译参数
> --prefix=/usr/local/nginx \ //指定安装目录
> --user=nginx \ //指定用户
> --group=nginx \ //指定组
> --with-http_ssl_module \ //启用SSL module
> --with-http_gunzip_module \ //启用 gunzip module
成功后提示如下:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
# make && make install //编译然后安装
测试 nginx 是否可用
# yum install elinks -y //elinks 是一款文本模式的浏览器
# cd /usr/local/nginx
# ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf //启动nginx 服务
# elinks --dump http://localhost/ //访问本地web服务,提示以下信息代表nginx正常运行
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to [1]nginx.org.
Commercial support is available at [2]nginx.com.
Thank you for using nginx.
-----------------安装PHP------------------
# yum install libxml2-devel //安装php依赖库
# tar -xjvf php-5.5.22.tar.bz2 //解压php源码包
# cd php-5.5.22
# ./configure \
> --prefix=/usr/local/php-fpm \ //指定安装目录
> --enable-fpm \ //启用 FPM 模式
> with-mysql \ //启用支持mysql
> with-mysqli //启用支持mysqli
# make && make install //编译安装
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //添加启动管理脚本
# chmod +x /etc/init.d/php-fpm
//生成配置文件
# cp /usr/local/php-fpm/etc/php-fpm.conf.default /usr/local/php-fpm/etc/php-fpm.conf
# service php-fpm start //启动 php-fpm 模式
# ps aux | grep php-fpm //启动成功 进程已经存在
root 14472 0.0 0.6 40752 3356 ? Ss 02:42 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) nobody 14473 0.0 0.5 40752 2984 ? S 02:42 0:00 php-fpm: pool www nobody 14474 0.0 0.5 40752 2984 ? S 02:42 0:00 php-fpm: pool www
-----------------Nginx PHP 整合-----------------
编辑 Nginx 配置文件
# vim /usr/loca/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm; //此处添加 index.php
}
以下部分去掉注释,并修改 fastcgi_param 的行
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 页面文件,进行测试
# cd /usr/loca/nginx/html
# vim index.php 写入以下内容
<?php
phpinfo(); //打印phpinfo函数
?>
# elinks --dump http://localhost/ //访问测试已经成功
[1]PHP logo
PHP Version 5.5.22
System Linux 6785021fbdc1 2.6.32-504.8.1.el6.x86_64 #1
SMP Wed Jan 28 21:11:36 UTC 2015 x86_64
Build Date Mar 16 2015 02:33:13
Configure Command ‘./configure‘ ‘--prefix=/usr/local/php-fpm‘
‘--enable-fpm‘ ‘--with-mysql‘ ‘--with-mysqli‘
Server API FPM/FastCGI
Virtual Directory disabled
Support
Configuration File /usr/local/php-fpm/lib
......
本文出自 “superTaodi” 博客,请务必保留此出处http://supertaodi.blog.51cto.com/7256234/1620778
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。