伺服器環境配置nginx / php / php-fpm(一)

來源:互聯網
上載者:User

標籤:非root   requests   stc   --   erro   kconfig   split   連接埠   重啟   

  1. 登陸,升級應用,查詢和關閉selinux
    yum update
    getenforcesetenforce 0vi /etc/selinux

     

  2. 添加非root使用者
    adduser deploypasswd deployusermod -a -G wheel deploy
    vi /etc/sudoers
    %wheel ALL=(ALL) ALL

     

  3. ssh配置
    ssh [email protected]ssh-keygenmkdir ~/.sshscp ~/.ssh/id_rsa.pub [email protected]:touch ~/.ssh/authorized_keyscat ~/id_rsa.pub >> ~/.ssh/authorized_keyschown -R deploy:deploy ~/.sshchmod 700 ~/.sshchmod 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;  
    //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;

     

  6. PHP-FPM配置
    sudo vi /etc/php-fpm.conf//修改以下兩處,1分鐘內子進程失敗達到10個就優雅重啟emergency_restart_threshold = 10emergency_restart_interval = 1m

    在設定檔中有 include=/etc/php-fpm.d/*.conf   , 表示池定義 pool definition 在php-fpm.d目錄下

    vi /etc/php-fpm.d/www.conf//修改使用者,盡量每個網站一個使用者user = deploygroup = deploy//與nginx請求處理的連接埠listen = 127.0.0.1:9000//伺服器記憶體除以進程佔用記憶體pm.max_children = 50//開啟服務時自動開啟的準備進程數pm.start_servers = 3//每個池的最大進程數pm.max_requests = 1000//慢日誌slowlog = /path/to/slowlog.logrequest_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/publicmkdir -p /home/deploy/apps/logschmod -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

     

  11. 檢查防火牆,檢查連接埠,檢查selinux /getenforce ,最後可以編輯一個phpinfo頁面放在網站根目錄,在主機設定好hosts映射到虛擬機器,終於可以在主機瀏覽器中輸入虛擬機器地址,見到php頁面了。
  12. 多虛擬機器參考http://www.androiddev.net/webserver-apache-to-nginx/
  13. 配置參考  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(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.