内容简介:原则:尽量使用yum repo安装CentOS 官方对第三方repo的说明使用nginx 官方提供的repo,配置文件
原则:尽量使用yum repo安装
CentOS 官方对第三方repo的说明 https://wiki.centos.org/zh/AdditionalResources/Repositories
nginx
使用nginx 官方提供的repo,配置文件 /etc/yum.repos.d/nginx.repo 文件内容如下
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
更多参看 http://nginx.org/en/linux_packages.html
php(fastcgi版)
因为要配合nginx,所以要选择fastcgi版的php-fpm, 这里选择 remi 源,这也是centos 官方推荐的 php 源之一。如下命令配置repo,将会配置好几个repo文件,但只有remi-safe.repo 是默认激活的,其他repo中的包有可能与系统文件冲突,所以在需要使用时在临时激活。
rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
如下命令安装php-fpm
yum --enablerepo=remi-php73 install php-fpm
remi维护了多个php版本,选用目前最新的7.3,通过--enablerepo临时激活该源。注意包名带 "-fpm" 否则是apache的模块版。注意一下安装进程,没有自动安装httpd。
按需要安装其他php扩展,下面是常用扩展的参考
yum --enablerepo=remi-php73 install php-gd php-gmp php-igbinary php-mbstring \ php-mcrypt php-memcached php-mysqli php-odbc php-pdo php-xml php-zip php-zlib
配置php-fpm。主要是文件 /etc/php-fpm.d/www.conf ,默认fastcgi进程数是动态管理的,根据机器内存、负载等控制进程数,下面是微小站点的配置,其中user/group 不改默认apache也行
user = nobody group = nobody pm = dynamic pm.max_children = 10 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 5
在nginx启用php
nginx主配置文件为 /etc/nginx/nginx.conf ,站点配置文件在 /etc/nginx/conf.d/*.conf ,默认参看主配置文件结尾处 include /etc/nginx/conf.d/*.conf 一行。
推荐习惯:把web站点文件放在 /var/www/html/ 目录下,每个站点一个子目录,下面以默认站点文件的配置为例,其他站点参考即可。更多参考 nignx官方文档 ,尤其是其中core模块 ngx_http_core_module
为默认站点 default.conf 创建目录 mkidr -p /var/www/html/default ,备份一下自带的的站点文件 cp /etc/nginx/conf.d/default.conf{,__original} ,参考下面示例修改 /etc/nginx/conf.d/default.conf 文件,注意:
- 其中 listen 80 default ; 一行表示这是默认站点,其他站点就不能加了。
- 原来在location / {...} 中的root 指令; 推荐直接放到server{...}节点中,目的是,在php 配置fastcgi_param中使用 $document_root 变量,而不是像默认配置文件里的再写一遍绝对路径,其中也可以省略掉root指令了。
- try_files $uri $uri/ /index.php; 一行是wordpress的伪静态rewrite规则;
- rewrite ^/feed /license.txt; 是把url重写到指定文件上
server {
listen 80 default;
server_name blog.path8.net;
#server_name blog.path8.net www.path8.net; #多域名
root /var/www/html/default;
#autoindex on;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /favicon.ico {
log_not_found off;
access_log off;
}
location /robots.txt {
log_not_found off;
access_log off;
}
location / {
# root /usr/share/nginx/html;
index index.html index.htm;
#try_files $uri $uri/ /index.php;
#rewrite ^/feed /license.txt;
}
#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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
修改完成后,nginx -t 测试配置文件,无误后启动(start)nginx及php-fpm,并设置自动启动(enable)
nginx -t systemctl start nginx systemctl status nginx systemctl enable nginx systemctl start php-fpm systemctl status php-fpm systemctl enable php-fpm
如果静态文件正常,php请求报错 File not found ,并且nginx error日志中有如下错误 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream 可去检查web文件权限与php-fpm用户是否匹配,还有是不是开着SELinux且没配置好规则。
new section
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Hyperledger Fabric环境搭建及环境测试(Mac环境)
- CV 环境很重要,各种环境搭建大全
- Openstack Queens 环境搭建(一)环境准备
- 分离Webpack开发环境与生产环境的配置
- Xcode配置测试环境和线上环境
- 重构之路:webpack区分生产环境和开发环境
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Text Processing in Python
David Mertz / Addison-Wesley Professional / 2003-6-12 / USD 54.99
Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing som......一起来看看 《Text Processing in Python》 这本书的介绍吧!
Markdown 在线编辑器
Markdown 在线编辑器
RGB HSV 转换
RGB HSV 互转工具