阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6部署Nginx + PHP5 服务器

90次阅读
没有评论

共计 2385 个字符,预计需要花费 6 分钟才能阅读完成。

在 CetnOS 6 (64 位) 操作系统上部署 Nginx and PHP5 服务器。这个过程通过 yum 命令进行 RPM 包安装。

可以参考 PHP 官方文档。

安装 一些必要的 YUM 库

root 用户执行:
# rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

安装 Nginx

添加 nginx 的 YUM 库配置文件 /etc/yum.repos.d/nginx.repo,
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/CentOS/$releasever/$basearch/
gpgcheck=0
enabled=1

root 用户执行:
# yum install nginx

安装 PHP 及重要插件 php-fpm

root 用户执行:
# yum install php-fpm php

配置、启动 php-fpm

配置 /etc/php.ini:
# 找到并取消注释,设置成:
cgi.fix_pathinfo=0

配置 /etc/php-fpm.d/www.conf:
# 找到并取消注释,设置成你希望管理 www 应用的用户(我这里统一用用户 theflash)
listen.owner = theflash
listen.group = theflash

启动 php-fpm 监听服务
# service php-fpm start

停止 php-fpm 监听服务
# service php-fpm stop

配置、启动 Nginx

创建一个网站根目录 /data/wwwroot,并更换目录所有者为 theflash。root 用户执行
# mkdir -p /data/wwwroot
# chown theflash:theflash /data/wwwroot -R

从此,以后就用用户 theflash 来登录并维护 /data/wwwroot 中的数据

直接分享我的配置 /etc/nginx/nginx.conf:
user theflash;

events {
}

http {
    include    /etc/nginx/mime.types;
    server {
        root    /data/wwwroot;

        location / {
            index  index.html index.htm index.php;
        }

        error_page  404              /404.html;

        location ~* \.php$ {
            fastcgi_index  index.php;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

启动 Nginx 服务器
# service nginx start

停止 Nginx 服务器
# service nginx stop

如果运行时修改了配置文件,需要重新加载 Nginx 服务器配置文件,而不需要停止 Nginx 服务器
# nginx -s reload

FAQ

如何解决“NO INPUT FILE SPECIFIED”的问题,当我们安装 PHP 和 NGINX 的时候

文章:英文原版

检查 php 文件是否拥有写权限,它的父目录都有执行权限?
#<– container folders should be granted execute permission
chmod a+x /data
chmod a+x /data/wwwroot

————————————– 分割线 ————————————–

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-03/115250.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2385字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中