服务器环境配置nginx / php / php-fpm(一)
- 登陆,升级应用,查询和关闭selinux
yum update
getenforce
setenforce 0
vi /etc/selinux - 添加非root用户
adduser deploy
passwd deploy
usermod -a -G wheel deploy
vi /etc/sudoers
%wheel ALL=(ALL) ALL - ssh配置

ssh deploy@123.456.78.90
ssh-keygen
mkdir ~/.ssh
scp ~/.ssh/id_rsa.pub deploy@123.456.78.90:
touch ~/.ssh/authorized_keys
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chown -R deploy:deploy ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
- 禁止密码与root登陆,先确定sudo权限,打开 /etc/ssh/sshd_config,修改 PasswordAuthentication 的值为 no,取消注释。修改PermitRootLogin同上。重启SSHD。
service sshd restart
- PHP、PHP-FPM 安装

sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm;
//32位地址 http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm; sudo yum -y --enablerepo=epel,remi,remi-php56 install php-fpm php-cli php-gd php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-devel;
- PHP-FPM配置
sudo vi /etc/php-fpm.conf
//修改以下两处,1分钟内子进程失败达到10个就优雅重启
emergency_restart_threshold = 10
emergency_restart_interval = 1m在配置文件中有 include=/etc/php-fpm.d/*.conf , 表示池定义 pool definition 在php-fpm.d目录下

vi /etc/php-fpm.d/www.conf
//修改用户,尽量每个网站一个用户
user = deploy
group = deploy
//与nginx请求处理的端口
listen = 127.0.0.1:9000
//服务器内存除以进程占用内存
pm.max_children = 50
//开启服务时自动开启的准备进程数
pm.start_servers = 3
//每个池的最大进程数
pm.max_requests = 1000
//慢日志
slowlog = /path/to/slowlog.log
request_slowlog_timeout = 5s
//最后重启服务
sudo service php-fpm restart
chkconfig php-fpm on
- 安装nginx
sudo yum install nginx;
sudo systemctl enable nginx.service;
sudo systemctl start nginx.service; - 建立网站目录与日志目录
mkdir -p /home/deploy/apps/example.com/current/public
mkdir -p /home/deploy/apps/logs
chmod -R +rx /home/deploy建立 /etc/nginx/conf.d/example.conf

server
{
listen 80;
server_name example.com;
index index.php;
client_max_body_size 50M;
error_log /home/deploy/apps/logs/example.error.log;
access_log /home/deploy/apps/logs/example.access.log;
root /home/deploy/apps/example.com/current/public;
location /
{
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php {
try_files $uri=404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
- 重启
sudo systemctl restart nginx.service
sudo chkconfig nginx on
//如果权限失败了, 以root权限启动
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf - 检查防火墙,检查端口,检查selinux /getenforce ,最后可以编辑一个phpinfo页面放在网站根目录,在主机设置好hosts映射到虚拟机,终于可以在主机浏览器中输入虚拟机地址,见到php页面了。
- 多虚拟机参考http://www.androiddev.net/webserver-apache-to-nginx/
- 配置参考 http://huoding.com/2013/10/23/290

server {
listen 80;
server_name foo.com; root /path;
index index.html index.htm index.php; location / {
try_files $uri $uri/ /index.php$is_args$args;
} location ~ \.php$ {
try_files $uri =404; include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
fastcgi_pass unix:/dev/shm/php-fpm.sock;
服务器环境配置nginx / php / php-fpm(一)的更多相关文章
- laravel5.8笔记一:安装与服务器环境配置
laravel版本:5.8 环境要求: PHP >= 7.1.3 OpenSSL PHP 扩展 PDO PHP 扩展 Mbstring PHP 扩展 Tokenizer PHP 扩展 XML P ...
- LNMP(linux+nginx+mysql+php)服务器环境配置【转载】
本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/05/17/2507102.h ...
- [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- ASP.NET Core 2.0发布/部署到Ubuntu服务器并配置Nginx反向代理
原文链接https://www.linuxidc.com/Linux/2017-12/149557.htm ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用AS ...
- Ubuntu 下 Apache2 和 PHP 服务器环境配置
Ubuntu 下 Apache2 和 PHP 服务器环境配置 1.简介 本文主要是 Ubuntu 下 Apache2 和 PHP 服务器环境配置方法,同样适用于 Debian 系统:Ubuntu 20 ...
- 零基础建站如何配置PHP运行环境 几种服务器环境配置的选择和方法
上次给大家分享了小白建站如何选择虚拟空间及服务器,及购买域名的基础知识,这些是硬性要求,你的网站要想运行起来,硬件只是基础,真正的技术是软件,关于PHP软件开发技术,后面我们会慢慢的分享给大家,今天主 ...
- linux系统上安装svn服务器 环境linux+nginx+svnserver
系统:Ubuntu 12.04 64位 lnmp环境 集成软件:PHP5.4.27.Nginx1.6.0.MySQL5.5.37 阿里云server svnserver有2种执行方式:独立server ...
- 超算云(GPU服务器)环境配置
最近在用并行超算云GPU服务器(中国国家网格12区)搭建毕设的环境,这里记录一下. 首先,超算云服务器的登录可以采用网页版.也可以采用客户端(超算云地址:https://cloud.paratera. ...
随机推荐
- Python 流程控制:while
while 语法如下,当条件为假时循环才退出,否则会一直循环下去: while 条件: 执行语句 当条件为假时,才会执行else语句: while 条件: 执行语句 else: 执行语句
- Swift 高级运算符
本文转载至 http://my.oschina.net/sunqichao/blog?disp=2&catalog=0&sort=time&p=2 除了基本操作符中所讲的运算符 ...
- uiimageview 异步加载图片
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ NSURL *url = ...
- 当新增页面和编辑页面使用同一jsp时
<c:if test="${type eq '1'}"><title>新增页面</title></c:if> <c:if te ...
- 设计模式之抽象工厂模式(Java实现)
“上次是我的不对,贿赂作者让我先讲来着,不过老婆大人大人有大量,不与我计较,这次还让我先把上次未讲完的应用场景部分给补充上去,有妻如此,夫复何求.”(说完,摸了摸跪的发疼的膝盖,咳咳,我发四我没笑!真 ...
- LeetCode——Lowest Common Ancestor of a Binary Search Tree
Description: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given no ...
- linux时间与Windows时间不一致的解决
一.首先要弄清几个概念:1. “系统时间”与“硬件时间” 系统时间: 一般说来就是我们执行 date命令看到的时间,linux系统下所有的时间调用(除了直接访问硬件时间的命令)都是使用的这个时间. ...
- angular -- ng-ui-route路由及其传递参数?script标签版
考虑到 多视图等因素,所以 angular 的路由考虑使用 ng-ui-route来做,而不使用 ng-route来做! <!DOCTYPE html> <html lang=&qu ...
- phpStorm 显示行号
- pta 习题集 数列求和-加强版
给定某数字AA(1≤A≤91≤A≤9)以及非负整数NN(0≤N≤1000000≤N≤100000),求数列之和S=A+AA+AAA+⋯+AA⋯AS=A+AA+AAA+⋯+AA⋯A(NN个AA).例如A ...