隨筆-179  評論-666  文章-29  trackbacks-0
          阿里云服務器優惠券
          1. 安裝 nginx 
            CentOS 7 沒有內建的 nginx,所以先到 nginx 官網  http://nginx.org/en/linux_packages.html#stable ,找到 CentOS 7 的 nginx-release package 檔案連結,然後如下安裝
            rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
            安裝後,會自動產生 yum 的 repository 設定(在 /etc/yum.repos.d/nginx.repo), 
            接下來便可以使用 yum 指令安裝 nginx
            yum install nginx
          2. 啟動 nginx 
            以前用 chkconfig 管理服務,CentOS 7 改用 systemctl 管理系統服務 
            立即啟動
            systemctl start nginx
            查看目前運作狀態
            systemctl status nginx
            查看 nginx 服務目前的啟動設定
            systemctl list-unit-files | grep nginx
            若是 disabled,可以改成開機自動啟動
            systemctl enable nginx
            若有設定防火牆,查看防火牆運行狀態,看是否有開啟 nginx 使用的 port
            firewall-cmd --state
            永久開放開啟防火牆的 http 服務
            firewall-cmd --permanent --zone=public --add-service=http
            firewall-cmd --reload
            列出防火牆 public 的設定
            firewall-cmd --list-all --zone=public
            經過以上設定,應該就可以使用瀏覽器訪問 nginx 的預設頁面。
          3. 安裝 PHP-FPM 
            使用 yum 安裝 php、php-fpm、php-mysql
            yum install php php-fpm php-mysql
            查看 php-fpm 服務目前的啟動設定 
            systemctl list-unit-files | grep php-fpm
            改成開機自動啟動
            systemctl enable php-fpm
            立即啟動
            systemctl start php-fpm
            查看目前運作狀態
            systemctl status php-fpm
          4. 修改 PHP-FPM listen 的方式 
            若想將 PHP-FPM listen 的方式,改成 unix socket,可以編輯 /etc/php-fpm.d/www.conf 
            listen = 127.0.0.1:9000
            改成
            listen = /var/run/php-fpm/php-fpm.sock
            然後重新啟動 php-fpm
            systemctl restart php-fpm
            註:不要改成 listen = /tmp/php-fcgi.sock (將 php-fcgi.sock 設定在 /tmp 底下), 因為系統產生 php-fcgi.sock 時,會放在 /tmp/systemd-private-*/tmp/php-fpm.sock 隨機私有目錄下, 除非把 /usr/lib/systemd/system/ 裡面的 PrivateTmp=true 設定改成 PrivateTmp=false, 但還是會產生其他問題,所以還是換個位置最方便 


            刪除之前的版本

            # yum remove php*

            rpm 安裝 Php7 相應的 yum源

            CentOS/RHEL 7.x:

            # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

            CentOS/RHEL 6.x:
            # rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

            yum安裝php7

            yum install php70w php70w-opcache
            安裝其他插件(選裝)
            注:如果安裝pear,需要安裝php70w-devel
            php70w
            php70w-bcmath
            php70w-cli
            php70w-common
            php70w-dba
            php70w-devel
            php70w-embedded
            php70w-enchant
            php70w-fpm
            php70w-gd
            php70w-imap
            php70w-interbase
            php70w-intl
            php70w-ldap
            php70w-mbstring
            php70w-mcrypt
            php70w-mysql
            php70w-mysqlnd
            php70w-odbc
            php70w-opcache
            php70w-pdo
            php70w-pdo_dblib
            php70w-pear
            php70w-pecl-apcu
            php70w-pecl-imagick
            php70w-pecl-xdebug
            php70w-pgsql
            php70w-phpdbg
            php70w-process
            php70w-pspell
            php70w-recode
            php70w-snmp
            php70w-soap
            php70w-tidy
            php70w-xml
            php70w-xmlrp

            編譯安裝php7

            配置(configure)、編譯(make)、安裝(make install)

            使用configure --help

            編譯安裝一定要指定定prefix,這是安裝目錄,會把所有文件限制在這個目錄,卸載時只需要刪除那個目錄就可以,如果不指定會安裝到很多地方,后邊刪除不方便。

            Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print `checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX

            注意
            內存小于1G安裝往往會出錯,在編譯參數后面加上一行內容--disable-fileinfo

            其他配置參數

            --exec-prefix=EXEC-PREFIX
            可以把體系相關的文件安裝到一個不同的位置,而不是PREFIX設置的地方.這樣做可以比較方便地在不同主機之間共享體系相關的文件
            --bindir=DIRECTORY
            為可執行程序聲明目錄,缺省是 EXEC-PREFIX/bin
            --datadir=DIRECTORY
            設置所安裝的程序需要的只讀文件的目錄.缺省是 PREFIX/share
            --sysconfdir=DIRECTORY
            用于各種各樣配置文件的目錄,缺省為 PREFIX/etc
            --libdir=DIRECTORY
            庫文件和動態裝載模塊的目錄.缺省是 EXEC-PREFIX/lib
            --includedir=DIRECTORY
            C 和 C++ 頭文件的目錄.缺省是 PREFIX/include
            --docdir=DIRECTORY
            文檔文件,(除 “man(手冊頁)”以外, 將被安裝到這個目錄.缺省是 PREFIX/doc
            --mandir=DIRECTORY
            隨著程序一起帶的手冊頁 將安裝到這個目錄.在它們相應的manx子目錄里. 缺省是PREFIX/man
            注意: 為了減少對共享安裝位置(比如 /usr/local/include) 的污染,configure 自動在 datadir, sysconfdir,includedir, 和 docdir 上附加一個 “/postgresql” 字串, 除非完全展開以后的目錄名字已經包含字串 “postgres” 或者 “pgsql”.比如,如果你選擇 /usr/local 做前綴,那么 C 的頭文件將安裝到 /usr/local/include/postgresql, 但是如果前綴是 /opt/postgres,那么它們將 被放進 /opt/postgres/include
            --with-includes=DIRECTORIES
            DIRECTORIES 是一系列冒號分隔的目錄,這些目錄將被加入編譯器的頭文件 搜索列表中.如果你有一些可選的包(比如 GNU Readline)安裝在 非標準位置,你就必須使用這個選項,以及可能還有相應的 --with-libraries 選項.
            --with-libraries=DIRECTORIES
            DIRECTORIES 是一系列冒號分隔的目錄,這些目錄是用于查找庫文件的. 如果你有一些包安裝在非標準位置,你可能就需要使用這個選項 (以及對應的--with-includes選項)
            --enable-XXX
            打開XXX支持
            --with-XXX
            制作XXX模塊

            • PHP FPM設定參考
              [global]
                       pid = /usr/local/php/var/run/php-fpm.pid
                       error_log = /usr/local/php/var/log/php-fpm.log
                       [www]
                       listen = /var/run/php-fpm/php-fpm.sock
                       user = www
                       group = www
                       pm = dynamic
                       pm.max_children = 800
                       pm.start_servers = 200
                       pm.min_spare_servers = 100
                       pm.max_spare_servers = 800
                       pm.max_requests = 4000
                       rlimit_files = 51200
                       listen.backlog = 65536
                       ;設 65536 的原因是-1 可能不是unlimited
                       ;說明 http://php.net/manual/en/install.fpm.configuration.php#104172
                       slowlog = /usr/local/php/var/log/slow.log
                       request_slowlog_timeout = 10
            • nginx.conf 設定參考 
              user nginx;
                       worker_processes 8;
                       error_log /var/log/nginx/error.log warn;
                       pid /var/run/nginx.pid;
                       events {
                        use epoll;
                        worker_connections 65535;
                       }
                       worker_rlimit_nofile 65535;
                       #若沒設定,可能出現錯誤:65535 worker_connections exceed open file resource limit: 1024
                       http {
                        include /etc/nginx/mime.types;
                        default_type application/octet-stream;
                        log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                             '$status $body_bytes_sent "$http_referer" '
                             '"$http_user_agent" "$http_x_forwarded_for"';
                        access_log /var/log/nginx/access.log main;
                        sendfile on;
                        tcp_nopush on;
                        keepalive_timeout 65;
                        server_names_hash_bucket_size 128;
                        client_header_buffer_size 32k;
                        large_client_header_buffers 4 32k;
                        client_max_body_size 8m;
                        server_tokens off;
                        client_body_buffer_size 512k;
                        # fastcgi
                        fastcgi_connect_timeout 300;
                        fastcgi_send_timeout 300;
                        fastcgi_read_timeout 300;
                        fastcgi_buffer_size 64k;
                        fastcgi_buffers 4 64k;
                        fastcgi_busy_buffers_size 128k;
                        fastcgi_temp_file_write_size 128k;
                        fastcgi_intercept_errors on;
                        #gzip (說明 http://nginx.org/en/docs/http/ngx_http_gzip_module.html)
                        gzip off;
                        gzip_min_length 1k;#1k以上才壓縮
                        gzip_buffers 32 4k;
                         #http://stackoverflow.com/questions/4888067/how-to-get-linux-kernel-page-size-programatically
                         #使用 getconf PAGESIZE 取得系統 one memory page size,
                        gzip_http_version 1.0;
                        gzip_comp_level 2;
                        gzip_types text/css text/xml application/javascript application/atom+xml application/rss+xml text/plain application/json;
                         #查看 nginx 的 mime.types 檔案(/etc/nginx/mime.types),裡面有各種類型的定義
                        gzip_vary on;
                        include /etc/nginx/conf.d/*.conf;
                       }
                       
              若出現出現錯誤:setrlimit(RLIMIT_NOFILE, 65535) failed (1: Operation not permitted) 
              先查看目前系統的設定值
              ulimit -n
              若設定值太小,修改 /etc/security/limits.conf
              vi /etc/security/limits.conf
              加上或修改以下兩行設定
              * soft nofile 65535
                       * hard nofile 65535



          阿里云服務器優惠券
          posted on 2016-08-10 13:44 Alpha 閱讀(6030) 評論(0)  編輯  收藏 所屬分類: Linux Nginx
          主站蜘蛛池模板: 怀远县| 搜索| 高青县| 广丰县| 大兴区| 宁乡县| 晋宁县| 星子县| 雷州市| 永德县| 肇源县| 辽阳县| 弋阳县| 永安市| 夹江县| 和平县| 万山特区| 汶川县| 丹棱县| 枣庄市| 江永县| 鄂托克前旗| 西乌珠穆沁旗| 宿州市| 大同市| 同心县| 竹山县| 高邑县| 南华县| 绍兴市| 阿合奇县| 明溪县| 三原县| 泊头市| 白玉县| 屏东市| 屯昌县| 昌吉市| 广宗县| 双城市| 牡丹江市|