码迷,mamicode.com
首页 > Web开发 > 详细

Centos 6.5 下部署企业网站平台Nginx+PHP

时间:2016-06-23 19:07:18      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:nginx

一、安装前准备

# yum -y install gcc gcc-c++ glibc automake autoconf libtool make

# yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

二、php-fpm安装

# wget http://mirrors.sohu.com/php/php-5.5.36.tar.bz2

# tar jxf php-5.5.36.tar.bz2

# cd php-5.5.36

# ./configure --prefix=/usr/local/php \

--enable-fpm --with-mcrypt --enable-mbstring --disable-pdo \

--with-curl --disable-debug --disable-rpath --enable-inline-optimization \

--with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm \

--enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex \

--with-mysql --with-mysqli --with-gd --with-jpeg-dir

# make && make install


配置php-fpm运行用户

# useradd www -M

# cd /usr/local/php/

# cp etc/php-fpm.default etc/php-fpm.conf

# vi etc/php-fpm.conf

修改
user = www
group = www


三、编译安装nginx

# yum install -y gcc gcc-c++ automake autoconf libtool make


1、安装插件安装包

首先需要安装pcre库,然后再安装Nginx

#安装pcre支持rewrite,也可以安装源码,注*安装源码时,指定pcre路径为解压源码的路径,而不是编译后的路径,否则会报错

make[1]: *** [/usr/local/pcre/Makefile] Error 127 错误)

# yum -y install pcre-devel pcre zlib zlib-devel openssl openssl-devel

源码安装PCRE(pcre支持rewrite库)

# cd /usr/local/src ;wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.bz2 ;tar jxf pcre-8.37.tar.bz2 ;cd pcre-8.37 && ./configure --prefix=/usr/local/pcre && make && make install

源码安装zlib库(zlib支持gzip压缩)

# cd /usr/local/src ;wget http://zlib.net/zlib-1.2.8.tar.gz ;tar zxf zlib-1.2.8.tar.gz ;cd zlib-1.2.8 && ./configure --prefix=/usr/local/zlib && make && make install

安装ssl(某些vps默认没装ssl)

# cd /usr/local/src ;wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz ;tar zxf openssl-1.0.2d.tar.gz


2、安装Nginx


# cd /usr/local/src ;wget -c http://nginx.org/download/nginx-1.8.1.tar.gz ;tar -zxf nginx-1.8.1.tar.gz ;cd nginx-1.8.1

#进入解压目录,然后sed修改Nginx版本信息为WS 

sed -i -e ‘s/1.8.1/g‘ -e ‘s/nginx\//WS/g‘ -e ‘s/"NGINX"/"WS"/g‘ src/core/nginx.h

预编译Nginx

# useradd www ;./configure --prefix=/usr/local/nginx \

--user=www \

--group=www \

--with-http_stub_status_module \

--with-http_ssl_module \

--with-pcre=/usr/local/src/pcre-8.37 \

--with-zlib=/usr/local/src/zlib-1.2.8 \

--with-openssl=/usr/local/src/openssl-1.0.2d

注意:

--with-pcre=/usr/local/src/pcre-8.37 指的是pcre-8.37 的源码路径。

--with-zlib=/usr/local/src/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。

make && make install

自此Nginx安装完毕


四、修改nginx.conf 文件,以支持php-fpm

# cd /usr/local/nginx/

# cp conf/nginx.conf conf/nginx.conf.bak

# vi conf/nginx.conf


其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


五、创建测试php文件

在/usr/local/nginx/html下创建info.php件,输入如下内容:

<?php

    echo phpinfo();

?>

六、启动服务

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

# /usr/local/nginx/sbin/nginx

七、浏览器访问

在浏览器访问:http://服务器ip/info.php,如果看到以下php信息,即说明环境部署成功。

技术分享

本文出自 “技术人生” 博客,请务必保留此出处http://gnucto.blog.51cto.com/3391516/1792219

Centos 6.5 下部署企业网站平台Nginx+PHP

标签:nginx

原文地址:http://gnucto.blog.51cto.com/3391516/1792219

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!