码迷,mamicode.com
首页 > Web开发 > 详细

服务器环境配置nginx / php / php-fpm

时间:2015-09-13 02:07:26      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

  1. 登陆,升级应用,查询和关闭selinux
    yum update
    getenforce
    setenforce 0
    vi /etc/selinux

     

  2. 添加非root用户
    adduser deploy
    passwd deploy
    usermod -a -G wheel deploy

     

  3. 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

     

  4. 禁止密码与root登陆,先确定sudo权限,打开 /etc/ssh/sshd_config,修改 PasswordAuthentication 的值为 no,取消注释。修改PermitRootLogin同上。重启SSHD。
    service sshd restart

     

  5. PHP、PHP-FPM 安装
    sudo rpm -Uvh  http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.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;

     

  6. 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

     

  7. 安装nginx
    sudo yum install nginx;
    sudo systemctl enable nginx.service;
    sudo systemctl start nginx.service;

     

  8. 建立网站目录与日志目录
    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

  9. 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;
        }
    }

     

  10. 重启
    sudo systemctl restart nginx.service
    sudo chkconfig nginx on
    //如果权限失败了, 以root权限启动 sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

     

服务器环境配置nginx / php / php-fpm

标签:

原文地址:http://www.cnblogs.com/fenle/p/4803977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!