centos6.x nginx安装 及php环境的配置

记录一下,只是做个备份。怕自己找不到

我的配置

centos6.7+nginx1.8+php5.3 我的php是之前装好的。yum安装,网上的教程很多。

nginx安装

我这里使用nginx的yum在线安装

  1. 添加源

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

  1. 安装源库

chmod +x nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm

  1. 安装nginx

yum -y install nginx

  1. 安装完成后的默认配置文件路径

默认nginx配置文件: /etc/nginx/nginx.conf 【nginx主要的配置文件】
默认nginx的ssl配置文件: /etc/nginx/conf.d/ssl.conf 【配置SSL证书的,也可以并入到nginx.conf文件里】
默认nginx的虚拟主机配置文件: /etc/nginx/conf.d/virtual.conf 【如同Apache的虚拟主机配置,也可以并入到nginx.conf文件里】
默认的web_root文件夹路径: /usr/share/nginx/html 【web目录夹,放置Magento主程序】

  1. 配置iptables

iptables -I INPUT 5 -p tcp –dport 80 -j ACCEPT
(这个步骤,我之前机器上已经装过apache所以就忽略了)

  1. 启动nginx

service nginx start
(如果没有权限,请加上sudo,即 sudo service nginx start)

  1. 设置开启启动:

chkconfig nginx on

打开IP地址 可见“Welcome to nginx!”表示安装成功。

=============================================================

另外:如果nginx设置目录在其他路径,一定要给o+x的权限,否则会报403forbidden

php安装配置

  1. 先修改nginx配置文件 /etc/nginx/conf.d/default.conf (修改前如果怕自己改错了,可以先备份一下)

location / {
root /var/www/nginx_html;
index index.php index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# 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 /var/www/nginx_html$fastcgi_script_name;
include fastcgi_params;
}
注nginx 是通过9000端口去查找php的,现在只是nginx去查找php,php是怎么找到nginx的呢?要配置php-fpm。
我修改了网站路径 root /var/www/nginx_html 大家在修改的时候,记得要修改一下文件夹的权限。

  1. php配置
    需要装一下php-fpm

yum -y install php-fpm

可能在这之前需要装一下其他的依赖:pcre, openssl,zlib 等等。

修改php-fpm配置 vim /etc/php-fpm.d/www.conf

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user’s group

; will be used.

; RPM: apache Choosed to be able to access some dir as httpd

user = nginx

; RPM: Keep a group allowed to write in log dir.

group = nginx

php通过php-fpm去开启9000端口去监听nginx。

最后,配置都修改完了之后,重启或启动服务

chkconfig php-fpm on #设置php-fpm自启动
service nginx restart #重新启动nginx
service php-fpm start #启动php-fpm

搞定!

    原文作者:不爱说话的言先生
    原文地址: https://www.jianshu.com/p/40b244594768
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞