docker nginx+php-fpm開発環境の構築

27690 ワード

一、ディレクトリの作成:
mkdir -p /data1/www/app;
mkdir -p /data1/www/logs;
mkdir -p /data1/www/php;
mkdir -p /data1/www/nginx;
mkdir -p /data1/www/php/fpm.d;
mkdir -p /data1/www/nginx/vhost;
chmod 777 -R /data1/www;

追加項目:vim/data 1/www/app/www.mydemo.com/index.php

    echo 22;
    phpinfo();

二、起動容器:
docker run -it --name=web_container --net=host -v /data1:/data1 centos /bin/bash;
yum -y install wget;
yum -y install initscripts;

三、nginxを取り付ける
依存関係の説明:
  • zlib:Nginxはgzipモジュールを提供し、zlibライブラリのサポートが必要です.
  • openssl:NginxはSSL機能
  • を提供する
  • pcre:アドレス書き換えrewrite機能
  • をサポート
    依存インストール:
    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel;
    

    依存性の検出:
    rpm -qa  zlib;
    rpm -qa  openssl;
    rmp -qa  pcre;
    

    nginxインストール
    wget http://nginx.org/download/nginx-1.10.3.tar.gz
    tar -zxvf nginx-1.10.3.tar.gz;
    cd nginx-1.10.3;
    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module;
    make && make install;
    

    ユーザーの作成
    groupadd  www
    useradd -r -g www  www
    

    ホスト上で追加プロファイルを変更する:vim/data 1/www/nginx/mime.types
    
    types {
        text/html                             html htm shtml;
        text/css                              css;
        text/xml                              xml;
        image/gif                             gif;
        image/jpeg                            jpeg jpg;
        application/javascript                js;
        application/atom+xml                  atom;
        application/rss+xml                   rss;
    
        text/mathml                           mml;
        text/plain                            txt;
        text/vnd.sun.j2me.app-descriptor      jad;
        text/vnd.wap.wml                      wml;
        text/x-component                      htc;
    
        image/png                             png;
        image/tiff                            tif tiff;
        image/vnd.wap.wbmp                    wbmp;
        image/x-icon                          ico;
        image/x-jng                           jng;
        image/x-ms-bmp                        bmp;
        image/svg+xml                         svg svgz;
        image/webp                            webp;
    
        application/font-woff                 woff;
        application/java-archive              jar war ear;
        application/json                      json;
        application/mac-binhex40              hqx;
        application/msword                    doc;
        application/pdf                       pdf;
        application/postscript                ps eps ai;
        application/rtf                       rtf;
        application/vnd.apple.mpegurl         m3u8;
        application/vnd.ms-excel              xls;
        application/vnd.ms-fontobject         eot;
        application/vnd.ms-powerpoint         ppt;
        application/vnd.wap.wmlc              wmlc;
        application/vnd.google-earth.kml+xml  kml;
        application/vnd.google-earth.kmz      kmz;
        application/x-7z-compressed           7z;
        application/x-cocoa                   cco;
        application/x-java-archive-diff       jardiff;
        application/x-java-jnlp-file          jnlp;
        application/x-makeself                run;
        application/x-perl                    pl pm;
        application/x-pilot                   prc pdb;
        application/x-rar-compressed          rar;
        application/x-redhat-package-manager  rpm;
        application/x-sea                     sea;
        application/x-shockwave-flash         swf;
        application/x-stuffit                 sit;
        application/x-tcl                     tcl tk;
        application/x-x509-ca-cert            der pem crt;
        application/x-xpinstall               xpi;
        application/xhtml+xml                 xhtml;
        application/xspf+xml                  xspf;
        application/zip                       zip;
    
        application/octet-stream              bin exe dll;
        application/octet-stream              deb;
        application/octet-stream              dmg;
        application/octet-stream              iso img;
        application/octet-stream              msi msp msm;
    
        application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
        application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
        application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;
    
        audio/midi                            mid midi kar;
        audio/mpeg                            mp3;
        audio/ogg                             ogg;
        audio/x-m4a                           m4a;
        audio/x-realaudio                     ra;
    
        video/3gpp                            3gpp 3gp;
        video/mp2t                            ts;
        video/mp4                             mp4;
        video/mpeg                            mpeg mpg;
        video/quicktime                       mov;
        video/webm                            webm;
        video/x-flv                           flv;
        video/x-m4v                           m4v;
        video/x-mng                           mng;
        video/x-ms-asf                        asx asf;
        video/x-ms-wmv                        wmv;
        video/x-msvideo                       avi;
    }

    新規fast_cig: vim/data1/www/nginx/fastcgi_params
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;

    vim/data1/www/nginx/nginx.conf
    user  www;
    worker_processes  5;
    
    error_log  logs/nginx-error.log;
    pid        nginx/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       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"';
        client_body_temp_path /tmp/client_body_temp_path;
        fastcgi_temp_path /tmp/fastcgi_temp_path;
        proxy_temp_path /tmp/proxy_temp_path;
        scgi_temp_path /tmp/scgi_temp;
        uwsgi_temp_path /tmp/uwsgi_temp_path;
    
        sendfile        on;
        keepalive_timeout  65;
        gzip  on;
        include vhost/*.conf;
    }

    プロファイル検出
    /usr/local/nginx/sbin/nginx -c /data1/www/nginx/nginx.conf -p /data1/www -t
    

    新規プロジェクト構成:vim/data 1/www/nginx/vhost/mydemo.com.conf
    server {
             listen       80 ;
             root /data1/www/app/www.mydemo.com/;
             server_name  www.mydemo.com mydemo.com;
    
             access_log   logs/nginx_www.mydemo.com-access_log  main;
             error_log    logs/nginx_www.mydemo.com-error_log;
             rewrite  "^/(.*)" /index.php/$1 last;
    
             location  / {
                       proxy_ignore_client_abort on;
                       fastcgi_pass 127.0.0.1:9023;
                       fastcgi_index index.php;
                       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                       #fastcgi_param  SCRIPT_URL         $script_uri;
                       #fastcgi_param  REQUEST_ID           $request_uid;
                       include fastcgi_params;
             }
    }

    nginxを起動するには:
    /usr/local/nginx/sbin/nginx -c /data1/www/nginx/nginx.conf -p /data1/www
    

    スムーズ再起動
    Kill -HUP  ${nginx_pid}
    

    四、php-fpmを取り付ける
    yum -y install gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-devel freetype-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt
    wget http://am1.php.net/get/php-7.2.0.tar.bz2/from/this/mirror ;
    tar -jxvf mirror;
    cd php-7.2.0;
    ./configure  --prefix=/usr/local/php --enable-fpm --enable-cli --enable-pcntl --with-curl;
    make && make install; 

    新規プロファイル:vim/data 1/www/php/php-fpm.conf
    [global]
    pid = php/php-fpm.pid
    error_log = logs/php-fpm.log
    emergency_restart_threshold = 20
    emergency_restart_interval = 60s
    process_control_timeout = 0
    process.max = 2048
    daemonize = yes
    rlimit_files = 65535
    rlimit_core = 67108864
    events.mechanism = epoll
    
    ; auto include phpfpm configure
    include = php/fpm.d/*.conf

    vim/data1/www/php/php.ini
    [PHP]
    engine = On
    short_open_tag = Off
    precision = 14
    output_buffering = 4096
    zlib.output_compression = Off
    implicit_flush = Off
    unserialize_callback_func =
    serialize_precision = -1
    disable_functions =
    disable_classes =
    zend.enable_gc = On
    expose_php = On
    max_execution_time = 30
    max_input_time = 60
    memory_limit = 128M
    error_reporting = E_ALL
    display_errors = On
    display_startup_errors = On
    log_errors = On
    log_errors_max_len = 1024
    ignore_repeated_errors = Off
    ignore_repeated_source = Off
    report_memleaks = On
    html_errors = On
    variables_order = "GPCS"
    request_order = "GP"
    register_argc_argv = Off
    auto_globals_jit = On
    post_max_size = 8M
    auto_prepend_file =
    auto_append_file =
    default_mimetype = "text/html"
    default_charset = "UTF-8"
    doc_root =
    user_dir =
    enable_dl = Off
    file_uploads = On
    upload_max_filesize = 2M
    max_file_uploads = 20
    allow_url_fopen = On
    allow_url_include = Off
    default_socket_timeout = 60
    [CLI Server]
    cli_server.color = On
    [Date]
    [filter]
    [iconv]
    [intl]
    [sqlite3]
    [Pcre]
    [Pdo]
    [Pdo_mysql]
    pdo_mysql.cache_size = 2000
    pdo_mysql.default_socket=
    [Phar]
    [mail function]
    SMTP = localhost
    smtp_port = 25
    mail.add_x_header = On
    [ODBC]
    odbc.allow_persistent = On
    odbc.check_persistent = On
    odbc.max_persistent = -1
    odbc.max_links = -1
    odbc.defaultlrl = 4096
    odbc.defaultbinmode = 1
    [Interbase]
    ibase.allow_persistent = 1
    ibase.max_persistent = -1
    ibase.max_links = -1
    ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
    ibase.dateformat = "%Y-%m-%d"
    ibase.timeformat = "%H:%M:%S"
    [MySQLi]
    mysqli.max_persistent = -1
    mysqli.allow_persistent = On
    mysqli.max_links = -1
    mysqli.cache_size = 2000
    mysqli.default_port = 3306
    mysqli.default_socket =
    mysqli.default_host =
    mysqli.default_user =
    mysqli.default_pw =
    mysqli.reconnect = Off
    [mysqlnd]
    mysqlnd.collect_statistics = On
    mysqlnd.collect_memory_statistics = On
    [OCI8]
    [PostgreSQL]
    pgsql.allow_persistent = On
    pgsql.auto_reset_persistent = Off
    pgsql.max_persistent = -1
    pgsql.max_links = -1
    pgsql.ignore_notice = 0
    pgsql.log_notice = 0
    [bcmath]
    bcmath.scale = 0
    [browscap]
    [Session]
    session.save_handler = files
    session.use_strict_mode = 0
    session.use_cookies = 1
    session.use_only_cookies = 1
    session.name = PHPSESSID
    session.auto_start = 0
    session.cookie_lifetime = 0
    session.cookie_path = /
    session.cookie_domain =
    session.cookie_httponly =
    session.serialize_handler = php
    session.gc_probability = 1
    session.gc_divisor = 1000
    session.gc_maxlifetime = 1440
    session.referer_check =
    session.cache_limiter = nocache
    session.cache_expire = 180
    session.use_trans_sid = 0
    session.sid_length = 26
    session.trans_sid_tags = "a=href,area=href,frame=src,form="
    session.sid_bits_per_character = 5
    [Assertion]
    zend.assertions = 1
    [COM]
    [mbstring]
    [gd]
    [exif]
    [Tidy]
    tidy.clean_output = Off
    [soap]
    soap.wsdl_cache_enabled=1
    soap.wsdl_cache_dir="/tmp"
    soap.wsdl_cache_ttl=86400
    soap.wsdl_cache_limit = 5
    [sysvshm]
    [ldap]
    ldap.max_links = -1
    [dba]
    [opcache]
    [curl]
    [openssl]

    新規プロジェクト構成:vim/data 1/www/php/fpm.d/mydemo.com.conf
     [mydemo.com]
    user = www
    group = www
    listen = 127.0.0.1:9023
    listen.allowed_clients = 127.0.0.1
    pm = dynamic
    pm.max_children = 512
    pm.start_servers = 5
    pm.min_spare_servers = 4
    pm.max_spare_servers = 64
    pm.max_requests = 1500
    
    ;pm.status_path = /dpool_monitor
    
    
    slowlog = logs/$pool-slow_log
    request_slowlog_timeout = 2
    
    request_terminate_timeout = 30
    catch_workers_output = no
    security.limit_extensions = ""
    
    access.log=logs/php-fpm_$pool.access.log
    access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"

    起動コマンド:
    /usr/local/php/sbin/php-fpm -c /data1/www/php/php.ini  -y /data1/www/php/php-fpm.conf  -p /data1/www

    スムーズ再起動:
    kill -USR2  fpm-pid