安装 Nginx
想在 CentOS 系统上安装 Nginx ,你得先去添加一个资源库,像这样:

vim /etc/yum.repos.d/nginx.repo
使用 vim 命令去打开 /etc/yum.repos.d/nginx.repo ,如果 nginx.repo 不存在,就会去创建一个这样的文件,打开以后按一下小 i 键,进入编辑模式,然后复制粘贴下面这几行代码,完成以后按 esc 键退出,再输入 :wq (保存并退出)

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
完成以后,我们就可以使用 yum 命令去安装 nginx 了,像这样:

yum install nginx
安装好以后测试一下 nginx 服务:

service nginx status
应该会返回:

nginx is stopped (nginx 已停止)
再测试一下 nginx 的配置文件:

nginx -t
应该会返回:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
... syntax is ok,... test is successful,说明配置文件没问题,同时这个结果里你可以找到 nginx 的配置文件 nginx.conf 所在的位置。

操纵 nginx 服务

操纵服务,可以使用使用 service 命令,它可以启动(start),重启(restart),或停止服务(stop),比如要启动 nginx 服务:

service nginx start
服务启动以后,你就可以在浏览器上使用服务器的 IP 地址,或者指向这个地址的域名访问服务器指定的目录了。你会看到类似下面的这些文字。

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 nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.

配置 php-fpm
要让 nginx 能够执行 php 文件,需要去安装一下 php-fpm,它直接包含在了 CentOS 资源库里,所以直接使用 yum 命令可以安装它:

yum install php-fpm
完成以后,可以检查一下 php-fpm 的运行状态,使用 service 命令:

service php-fpm status
返回:

php-fpm is stopped(php-fpm 已停止)
启动 php-fpm 同样可以使用 service 命令:

service php-fpm start

让 nginx 可以执行 php
现在我们应该就可以让 nginx 去执行 php 了。不过你需要修改一下 nginx 的配置文件,之前我们在配置虚拟主机的时候,创建了一个 nginx.ninghao.net.conf 的配置文件,需要去修改下 nginx 的这个配置文件,才能去执行 php 。使用 vim 命令去编辑它:

vim /etc/nginx/conf.d/www.96net.com.cn.conf
注意你的配置文件不一定叫 nginx.www.96net.com.cn,应该是你自己命名的配置文件。打开以后,找到下面这段字样的代码:

# 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 /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
这是 nginx 默认给我们的用来执行 php 的配置,从 location 开始取消注释,会让这个配置生效,然后我们还得简单去修改一下:

# 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;
}
注意 root 那里仍然是被注释掉的,还有 SCRIPT_FILENAME 后面修改了一下,把 /scripts 换成了 $document_root 。保存并退出。然后重新启动 nginx:

service nginx restart

安装 php 扩展

现在,我们有了可以提供 web 服务的 nginx ,并且安装了 php-fpm ,配置了 nginx 可以让它去执行 php ,也安装了数据库管理系统。不过在运行真正的网站的时候,我们还需要为 php 安装一些额外的扩展,比如 处理 mysql 数据库的 mysql 扩展,缓存功能的 apc 扩展,处理图像的 gd 扩展等等。安装它们同样可以使用 yum 命令。

yum install php-pecl-apc php-mysql php-gd php-mcrypt php-pear php-mbstring php-xmlrpc php-dom

上面安装了一些 php 的扩展,如果你发现在安装网站的时候提示需要安装其它的扩展,同样可以使用 yum 命令去安装。安装完成以后,需要重启一下 php-fpm :

service php-fpm restart

最新文章

  1. 主流 SQLServer 迁移到 MySQL 工具对比
  2. 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误
  3. odeforces Beta Round #77 (Div. 2 Only)
  4. 用jquery实现简单的表单验证
  5. c# Json Dictionary序列化和反序列化
  6. git 远程版本库
  7. s3cmd的安装与配置
  8. C语言头文件书写
  9. AnonymousType匿名类型和对象之间的转换
  10. ural 1874 Football Goal
  11. 【Win7激活工具2013版下载】适用于旗舰版、家庭高级版等所有版本32/64位 OEM激活
  12. QML插件扩展(一)
  13. 两个标签页定位第二个标签页元素时显示element not visible
  14. vector作为函数返回值
  15. 了解java虚拟机—在TALB上分配对象(10)
  16. ABP之展现层(导航菜单)
  17. Software-Defined Networking:A Comprehensive Survey--Day4
  18. [原][JSBSim]基于qt代码实现:TCP|UDP与飞行模拟软件JSBSim的通信,现实模型飞行!
  19. 『TensorFlow』DCGAN生成动漫人物头像_下
  20. .NET Reflector注册机激活方法

热门文章

  1. python在类中使用__slot__属性
  2. OGG复制进程延迟不断增长
  3. SpringMVC的@ResponseBody注解简介
  4. Flask 之装饰器有关
  5. ORM大结局
  6. django 修改字段后,同步数据库,失败:django.db.utils.InternalError: (1054, "Unknown column 'api_config.project_id_id' in 'field list'")
  7. 微信公众号号开发(Java)
  8. Your first HTML form
  9. postman使用动态token发post请求小结
  10. Oracle查询中文乱码