安装前准备
yum -y install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel
rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm
首先安装Nginx,采用编译安装
# 切换到下载目录
cd /usr/local/src
下载源码包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
# 如果没有wget目录 使用:yum install wget 下载wget命令
解压源码包
tar zxvf nginx-1.6.2.tar.gz
切换到解压目录
cd nginx-1.6.2
编译前配置
./configure --prefix=/usr/local/nginx
编译安装
make && make install
Nginx安装完毕,启动命令
/usr/local/nginx/sbin/nginx
安装php-fpm5.6
yum -y install php56w-fpm
修改配置让Nginx将访问到PHP文件转发给php-fpm处理
vi /usr/local/nginx/conf/nginx.conf
找到
location / {
root html;
index index.html index.htm;
}
修改为
location / {
root html;
index index.html index.htm index.php;
}
然后在service{}里添加
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;
}
/usr/local/nginx/html/为存放PHP文件的目录,可修改
启动php-fpm
service php-fpm start
平滑的重启Nginx
/usr/local/nginx/sbin/nginx -s reload
补充:
还可安装一些PHP常用模块和设置一些开机服务
安装PHP常用模块
yum -y install php56w-devel php56w-gd php56w-mbstring php56w-mysql php56w-pdo php56w-xml
设置开机启动
# 设置MySQL开机启动
chkconfig mysqld on
# 设置php-fpm开机启动
chkconfig php-fpm on