├── .ebextensions ├── 01_setup.config ├── 02_cloudwatch_logs.config_example └── setup │ ├── config │ ├── cron │ │ └── healthd.nginx.conf │ ├── nginx │ │ ├── gzip.conf_example │ │ ├── nginx.conf │ │ ├── php.conf-7.1 │ │ └── real_ip.conf_example │ └── php-fpm │ │ ├── php-fpm.conf │ │ └── www.conf │ ├── hooks │ ├── appdeploy │ │ ├── enact │ │ │ ├── 97_custom_logging.sh │ │ │ ├── 98_nginx_env.sh │ │ │ └── 99_reload_app_server.sh │ │ └── post │ │ │ ├── 01_monitor_httpd_pid.sh │ │ │ └── 02_restart_healthd.sh │ ├── configdeploy │ │ └── enact │ │ │ ├── 98_nginx_env.sh │ │ │ └── 99_reload_app_server.sh │ └── restartappserver │ │ ├── enact │ │ └── 01_restart.sh │ │ └── pre │ │ └── 99_nginx_env.sh │ ├── support │ └── conf │ │ ├── nginx.logrotate.conf │ │ └── php-fpm.logrotate.conf │ └── tasks │ ├── bundlelogs.d │ ├── nginx.conf │ └── php-fpm.conf │ ├── publishlogs.d │ ├── nginx.conf │ └── php-fpm.conf │ ├── systemtaillogs.d │ ├── nginx.conf │ └── php-fpm.conf │ └── taillogs.d │ ├── nginx.conf │ └── php-fpm.conf ├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── index.php └── info.php /.ebextensions/01_setup.config: -------------------------------------------------------------------------------- 1 | ## Install nginx and php71-fpm 2 | packages: 3 | yum: 4 | nginx: [] 5 | php71-fpm: [] 6 | 7 | ## Stop apache, add nginx / php-fpm boot up and environment config 8 | commands: 9 | 010_stop_apache: 10 | test: service httpd status | grep running 11 | command: service httpd stop 12 | 020_nginx_env: 13 | command: touch /etc/nginx/fastcgi_params_env 14 | 030_nginx_boot: 15 | command: chkconfig nginx on 16 | 040_php_fpm_boot: 17 | command: chkconfig php-fpm on 18 | 050_create_log_dirs: 19 | command: mkdir -p /var/log/nginx/healthd /var/log/nginx/rotated /var/log/php-fpm/7.1/rotated 20 | 060_php_log_perms: 21 | command: chown -R webapp. /var/log/php-fpm 22 | 070_nginx_log_perms: 23 | command: chown -R nginx. /var/log/nginx 24 | 25 | ## Update the Elasticbeanstalk environment and config files 26 | container_commands: 27 | ## Make all .sh scripts executable 28 | 001_sh_executable: 29 | command: find .ebextensions/setup/hooks/ -type f -iname "*.sh" -exec chmod +x {} \; 30 | ## Copy all custom platform scripts and config files 31 | 010_hooks: 32 | command: cp -rf .ebextensions/setup/hooks/* /opt/elasticbeanstalk/hooks/ 33 | 020_support: 34 | command: cp -rf .ebextensions/setup/support/* /opt/elasticbeanstalk/support/ 35 | 030_tasks: 36 | command: cp -rf .ebextensions/setup/tasks/* /opt/elasticbeanstalk/tasks/ 37 | ## Copy custom nginx and php-fpm config files 38 | 040_nginx_conf: 39 | command: cp -f .ebextensions/setup/config/nginx/nginx.conf /etc/nginx/nginx.conf 40 | 050_nginx_default_conf: 41 | command: cp -f .ebextensions/setup/config/nginx/php.conf-7.1 /etc/nginx/default.d/php.conf-7.1 42 | 060_php_fpm_conf: 43 | command: cp -f .ebextensions/setup/config/php-fpm/php-fpm.conf /etc/php-fpm-7.1.conf 44 | 070_www_pool_conf: 45 | command: cp -f .ebextensions/setup/config/php-fpm/www.conf /etc/php-fpm-7.1.d/www.conf 46 | 080_healthd_nginx_cron_conf: 47 | command: cp -f .ebextensions/setup/config/cron/healthd.nginx.conf /etc/cron.hourly/cron.logcleanup.elasticbeanstalk.healthd.nginx.conf 48 | 090_cron_executable: 49 | command: chmod +x /etc/cron.hourly/cron.logcleanup.elasticbeanstalk.healthd.nginx.conf 50 | ## Uncomment the following for gzip and real_ip configs. Be sure to rename the files in 51 | ## the /setup/config/nginx directory!! 52 | #100_gzip_conf: 53 | # command: cp -f .ebextensions/setup/config/nginx/gzip.conf /etc/nginx/conf.d/gzip.conf 54 | #110_real_ip_conf: 55 | # command: cp -f .ebextensions/setup/config/nginx/real_ip.conf /etc/nginx/conf.d/real_ip.conf 56 | -------------------------------------------------------------------------------- /.ebextensions/02_cloudwatch_logs.config_example: -------------------------------------------------------------------------------- 1 | ## set up custom logging for nginx and php-fpm 2 | 3 | packages: 4 | yum: 5 | awslogs: [] 6 | 7 | files: 8 | "/etc/awslogs/config/nginx-php.conf" : 9 | mode: "000600" 10 | owner: root 11 | group: root 12 | content: | 13 | [/var/php-fpm/7.1/www-error.log] 14 | log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/php-fpm/7.1/www-error.log"]]}` 15 | log_stream_name = {instance_id} 16 | file = /var/log/php-fpm/7.1/www-error.log 17 | 18 | [/var/log/nginx/access.log] 19 | log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/nginx/access.log "]]}` 20 | log_stream_name = {instance_id} 21 | file = /var/log/nginx/access.log 22 | 23 | [/var/log/nginx/error.log] 24 | log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/nginx/error.log "]]}` 25 | log_stream_name = {instance_id} 26 | file = /var/log/nginx/error.log 27 | 28 | commands: 29 | "01": 30 | command: chkconfig awslogs on 31 | "02": 32 | command: service awslogs restart -------------------------------------------------------------------------------- /.ebextensions/setup/config/cron/healthd.nginx.conf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | find /var/log/nginx/healthd -type f | grep -v application.log.`date -u +"%Y-%m-%d-%H"` | xargs rm -f 3 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/nginx/gzip.conf_example: -------------------------------------------------------------------------------- 1 | # Server gzip config 2 | gzip on; 3 | gzip_buffers 8 16k; 4 | gzip_vary on; 5 | gzip_disable "msie6"; 6 | gzip_min_length 1100; 7 | gzip_proxied any; 8 | gzip_types 9 | text/css 10 | text/x-component 11 | application/x-javascript 12 | application/javascript 13 | text/javascript 14 | text/x-js 15 | text/richtext 16 | image/svg+xml 17 | text/plain 18 | text/xsd 19 | text/xsl 20 | text/xml 21 | image/bmp 22 | application/java 23 | application/msword 24 | application/vnd.ms-fontobject 25 | application/x-msdownload 26 | image/x-icon 27 | image/webp 28 | application/json 29 | application/vnd.ms-access 30 | application/vnd.ms-project 31 | application/x-font-otf 32 | application/vnd.ms-opentype 33 | application/vnd.oasis.opendocument.database 34 | application/vnd.oasis.opendocument.chart 35 | application/vnd.oasis.opendocument.formula 36 | application/vnd.oasis.opendocument.graphics 37 | application/vnd.oasis.opendocument.spreadsheet 38 | application/vnd.oasis.opendocument.text 39 | audio/ogg 40 | application/pdf 41 | application/vnd.ms-powerpoint 42 | application/x-shockwave-flash 43 | image/tiff 44 | application/x-font-ttf 45 | audio/wav 46 | application/vnd.ms-write 47 | application/font-woff 48 | application/font-woff2 49 | application/vnd.ms-excel; 50 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | # For more information on configuration, see: 2 | # * Official English Documentation: http://nginx.org/en/docs/ 3 | # * Official Russian Documentation: http://nginx.org/ru/docs/ 4 | 5 | user nginx; 6 | worker_processes auto; 7 | error_log /var/log/nginx/error.log; 8 | pid /var/run/nginx.pid; 9 | 10 | # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. 11 | include /usr/share/nginx/modules/*.conf; 12 | 13 | events { 14 | worker_connections 1024; 15 | } 16 | 17 | http { 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | log_format healthd '$msec"$uri"' 23 | '$status"$request_time"$upstream_response_time"' 24 | '$http_x_forwarded_for'; 25 | 26 | sendfile on; 27 | tcp_nopush on; 28 | tcp_nodelay on; 29 | keepalive_timeout 65; 30 | types_hash_max_size 2048; 31 | server_tokens off; 32 | 33 | include /etc/nginx/mime.types; 34 | default_type application/octet-stream; 35 | 36 | # Load modular configuration files from the /etc/nginx/conf.d directory. 37 | # See http://nginx.org/en/docs/ngx_core_module.html#include 38 | # for more information. 39 | include /etc/nginx/conf.d/*.conf; 40 | 41 | index index.html index.htm; 42 | 43 | server { 44 | listen 80 default_server; 45 | listen [::]:80 default_server; 46 | server_name localhost; 47 | root /var/app/current; 48 | 49 | if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { 50 | set $year $1; 51 | set $month $2; 52 | set $day $3; 53 | set $hour $4; 54 | } 55 | 56 | access_log /var/log/nginx/access.log main; 57 | access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; 58 | 59 | # Load configuration files for the default server block. 60 | include /etc/nginx/default.d/*.conf; 61 | 62 | # This will pass all unknown URIs to index.php. Most frameworks 63 | # work this way. Remove, if you don't need this. 64 | location / { 65 | try_files $uri $uri/ index.php?$args; 66 | } 67 | 68 | # redirect server error pages to the static page /40x.html 69 | # 70 | error_page 404 /404.html; 71 | location = /40x.html { 72 | } 73 | 74 | # redirect server error pages to the static page /50x.html 75 | # 76 | error_page 500 502 503 504 /50x.html; 77 | location = /50x.html { 78 | } 79 | 80 | # deny access to .htaccess files, if Apache's document root 81 | # concurs with nginx's one 82 | # 83 | location ~ /\.ht { 84 | deny all; 85 | } 86 | } 87 | 88 | # Settings for a TLS enabled server. 89 | # 90 | # server { 91 | # listen 443 ssl http2 default_server; 92 | # listen [::]:443 ssl http2 default_server; 93 | # server_name _; 94 | # root /var/app/current; 95 | # 96 | # ssl_certificate "/etc/pki/nginx/server.crt"; 97 | # ssl_certificate_key "/etc/pki/nginx/private/server.key"; 98 | # # It is *strongly* recommended to generate unique DH parameters 99 | # # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 100 | # #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; 101 | # ssl_session_cache shared:SSL:1m; 102 | # ssl_session_timeout 10m; 103 | # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 104 | # ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; 105 | # ssl_prefer_server_ciphers on; 106 | # 107 | # # Load configuration files for the default server block. 108 | # include /etc/nginx/default.d/*.conf; 109 | # 110 | # location / { 111 | # } 112 | # 113 | # error_page 404 /404.html; 114 | # location = /40x.html { 115 | # } 116 | # 117 | # error_page 500 502 503 504 /50x.html; 118 | # location = /50x.html { 119 | # } 120 | # 121 | # # deny access to .htaccess files, if Apache's document root 122 | # # concurs with nginx's one 123 | # # 124 | # location ~ /\.ht { 125 | # deny all; 126 | # } 127 | # 128 | # } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/nginx/php.conf-7.1: -------------------------------------------------------------------------------- 1 | # pass the PHP scripts to FastCGI server 2 | # 3 | # See conf.d/php-fpm.conf for socket configuration 4 | # 5 | 6 | index index.php index.html index.htm; 7 | 8 | # Handle php files and path info 9 | location ~ \.php(/.*)?$ { 10 | fastcgi_intercept_errors on; 11 | 12 | # regex to split $uri to $fastcgi_script_name and $fastcgi_path 13 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 14 | 15 | # Check that the PHP script exists before passing it 16 | try_files $fastcgi_script_name =404; 17 | 18 | # Bypass the fact that try_files resets $fastcgi_path_info 19 | # see: http://trac.nginx.org/nginx/ticket/321 20 | set $path_info $fastcgi_path_info; 21 | fastcgi_param PATH_INFO $path_info; 22 | 23 | fastcgi_index index.php; 24 | include fastcgi.conf; 25 | include fastcgi_params_env; 26 | fastcgi_pass php-fpm; 27 | } 28 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/nginx/real_ip.conf_example: -------------------------------------------------------------------------------- 1 | # Set the IP Address correctly from proxy / load balancer. 2 | # This example work with AWS. Change the CIDR range below to 3 | # match your environment, if different. 4 | set_real_ip_from 172.31.0.0/16; 5 | real_ip_header X-Forwarded-For; 6 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/php-fpm/php-fpm.conf: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;; 2 | ; FPM Configuration ; 3 | ;;;;;;;;;;;;;;;;;;;;; 4 | 5 | ; All relative paths in this configuration file are relative to PHP's install 6 | ; prefix. 7 | 8 | ; Include one or more files. If glob(3) exists, it is used to include a bunch of 9 | ; files from a glob(3) pattern. This directive can be used everywhere in the 10 | ; file. 11 | include=/etc/php-fpm-7.1.d/*.conf 12 | ;include=/etc/php-7.1.d/*.ini 13 | 14 | ;;;;;;;;;;;;;;;;;; 15 | ; Global Options ; 16 | ;;;;;;;;;;;;;;;;;; 17 | 18 | [global] 19 | ; Pid file 20 | ; Default Value: none 21 | pid = /var/run/php-fpm/php-fpm-7.1.pid 22 | 23 | ; Error log file 24 | ; If it's set to "syslog", log is sent to syslogd instead of being written 25 | ; in a local file. 26 | ; Default Value: /var/log/php-fpm.log 27 | error_log = /var/log/php-fpm/7.1/error.log 28 | 29 | ; syslog_facility is used to specify what type of program is logging the 30 | ; message. This lets syslogd specify that messages from different facilities 31 | ; will be handled differently. 32 | ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON) 33 | ; Default Value: daemon 34 | ;syslog.facility = daemon 35 | 36 | ; syslog_ident is prepended to every message. If you have multiple FPM 37 | ; instances running on the same server, you can change the default value 38 | ; which must suit common needs. 39 | ; Default Value: php-fpm 40 | ;syslog.ident = php-fpm 41 | 42 | ; Log level 43 | ; Possible Values: alert, error, warning, notice, debug 44 | ; Default Value: notice 45 | ;log_level = notice 46 | 47 | ; If this number of child processes exit with SIGSEGV or SIGBUS within the time 48 | ; interval set by emergency_restart_interval then FPM will restart. A value 49 | ; of '0' means 'Off'. 50 | ; Default Value: 0 51 | ;emergency_restart_threshold = 0 52 | 53 | ; Interval of time used by emergency_restart_interval to determine when 54 | ; a graceful restart will be initiated. This can be useful to work around 55 | ; accidental corruptions in an accelerator's shared memory. 56 | ; Available Units: s(econds), m(inutes), h(ours), or d(ays) 57 | ; Default Unit: seconds 58 | ; Default Value: 0 59 | ;emergency_restart_interval = 0 60 | 61 | ; Time limit for child processes to wait for a reaction on signals from master. 62 | ; Available units: s(econds), m(inutes), h(ours), or d(ays) 63 | ; Default Unit: seconds 64 | ; Default Value: 0 65 | ;process_control_timeout = 0 66 | 67 | ; The maximum number of processes FPM will fork. This has been design to control 68 | ; the global number of processes when using dynamic PM within a lot of pools. 69 | ; Use it with caution. 70 | ; Note: A value of 0 indicates no limit 71 | ; Default Value: 0 72 | ;process.max = 128 73 | 74 | ; Specify the nice(2) priority to apply to the master process (only if set) 75 | ; The value can vary from -19 (highest priority) to 20 (lower priority) 76 | ; Note: - It will only work if the FPM master process is launched as root 77 | ; - The pool process will inherit the master process priority 78 | ; unless it specified otherwise 79 | ; Default Value: no set 80 | ;process.priority = -19 81 | 82 | ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. 83 | ; Default Value: yes 84 | daemonize = yes 85 | 86 | ; Set open file descriptor rlimit for the master process. 87 | ; Default Value: system defined value 88 | ;rlimit_files = 1024 89 | 90 | ; Set max core size rlimit for the master process. 91 | ; Possible Values: 'unlimited' or an integer greater or equal to 0 92 | ; Default Value: system defined value 93 | ;rlimit_core = 0 94 | 95 | ; Specify the event mechanism FPM will use. The following is available: 96 | ; - select (any POSIX os) 97 | ; - poll (any POSIX os) 98 | ; - epoll (linux >= 2.5.44) 99 | ; Default Value: not set (auto detection) 100 | ;events.mechanism = epoll 101 | 102 | ; When FPM is build with systemd integration, specify the interval, 103 | ; in second, between health report notification to systemd. 104 | ; Set to 0 to disable. 105 | ; Available Units: s(econds), m(inutes), h(ours) 106 | ; Default Unit: seconds 107 | ; Default value: 10 108 | ;systemd_interval = 10 109 | 110 | ;;;;;;;;;;;;;;;;;;;; 111 | ; Pool Definitions ; 112 | ;;;;;;;;;;;;;;;;;;;; 113 | 114 | ; Multiple pools of child processes may be started with different listening 115 | ; ports and different management options. The name of the pool will be 116 | ; used in logs and stats. There is no limitation on the number of pools which 117 | ; FPM can handle. Your system will tell you anyway :) 118 | 119 | ; See /etc/php-fpm-7.1.d/*.conf 120 | -------------------------------------------------------------------------------- /.ebextensions/setup/config/php-fpm/www.conf: -------------------------------------------------------------------------------- 1 | ; Start a new pool named 'www'. 2 | ; the variable $pool can we used in any directive and will be replaced by the 3 | ; pool name ('www' here) 4 | [www] 5 | 6 | ; Per pool prefix 7 | ; It only applies on the following directives: 8 | ; - 'access.log' 9 | ; - 'slowlog' 10 | ; - 'listen' (unixsocket) 11 | ; - 'chroot' 12 | ; - 'chdir' 13 | ; - 'php_values' 14 | ; - 'php_admin_values' 15 | ; When not set, the global prefix (or @php_fpm_prefix@) applies instead. 16 | ; Note: This directive can also be relative to the global prefix. 17 | ; Default Value: none 18 | ;prefix = /path/to/pools/$pool 19 | 20 | ; Unix user/group of processes 21 | ; Note: The user is mandatory. If the group is not set, the default user's group 22 | ; will be used. 23 | ; RPM: apache user chosen to provide access to the same directories as httpd 24 | user = webapp 25 | ; RPM: Keep a group allowed to write in log dir. 26 | group = webapp 27 | 28 | ; The address on which to accept FastCGI requests. 29 | ; Valid syntaxes are: 30 | ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on 31 | ; a specific port; 32 | ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on 33 | ; a specific port; 34 | ; 'port' - to listen on a TCP socket to all addresses 35 | ; (IPv6 and IPv4-mapped) on a specific port; 36 | ; '/path/to/unix/socket' - to listen on a unix socket. 37 | ; Note: This value is mandatory. 38 | listen = /var/run/php-fpm/www.sock 39 | 40 | ; Set listen(2) backlog. 41 | ; Default Value: 511 42 | ;listen.backlog = 511 43 | 44 | ; Set permissions for unix socket, if one is used. In Linux, read/write 45 | ; permissions must be set in order to allow connections from a web server. 46 | ; Default Values: user and group are set as the running user 47 | ; mode is set to 0660 48 | ;listen.owner = nobody 49 | ;listen.group = nobody 50 | ;listen.mode = 0660 51 | 52 | ; When POSIX Access Control Lists are supported you can set them using 53 | ; these options, value is a comma separated list of user/group names. 54 | ; When set, listen.owner and listen.group are ignored 55 | listen.acl_users = apache,nginx,webapp 56 | ;listen.acl_groups = 57 | 58 | ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. 59 | ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original 60 | ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address 61 | ; must be separated by a comma. If this value is left blank, connections will be 62 | ; accepted from any ip address. 63 | ; Default Value: any 64 | listen.allowed_clients = 127.0.0.1 65 | 66 | ; Specify the nice(2) priority to apply to the pool processes (only if set) 67 | ; The value can vary from -19 (highest priority) to 20 (lower priority) 68 | ; Note: - It will only work if the FPM master process is launched as root 69 | ; - The pool processes will inherit the master process priority 70 | ; unless it specified otherwise 71 | ; Default Value: no set 72 | ; process.priority = -19 73 | 74 | ; Choose how the process manager will control the number of child processes. 75 | ; Possible Values: 76 | ; static - a fixed number (pm.max_children) of child processes; 77 | ; dynamic - the number of child processes are set dynamically based on the 78 | ; following directives. With this process management, there will be 79 | ; always at least 1 children. 80 | ; pm.max_children - the maximum number of children that can 81 | ; be alive at the same time. 82 | ; pm.start_servers - the number of children created on startup. 83 | ; pm.min_spare_servers - the minimum number of children in 'idle' 84 | ; state (waiting to process). If the number 85 | ; of 'idle' processes is less than this 86 | ; number then some children will be created. 87 | ; pm.max_spare_servers - the maximum number of children in 'idle' 88 | ; state (waiting to process). If the number 89 | ; of 'idle' processes is greater than this 90 | ; number then some children will be killed. 91 | ; ondemand - no children are created at startup. Children will be forked when 92 | ; new requests will connect. The following parameter are used: 93 | ; pm.max_children - the maximum number of children that 94 | ; can be alive at the same time. 95 | ; pm.process_idle_timeout - The number of seconds after which 96 | ; an idle process will be killed. 97 | ; Note: This value is mandatory. 98 | pm = dynamic 99 | 100 | ; The number of child processes to be created when pm is set to 'static' and the 101 | ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. 102 | ; This value sets the limit on the number of simultaneous requests that will be 103 | ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. 104 | ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP 105 | ; CGI. The below defaults are based on a server without much resources. Don't 106 | ; forget to tweak pm.* to fit your needs. 107 | ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' 108 | ; Note: This value is mandatory. 109 | pm.max_children = 30 110 | 111 | ; The number of child processes created on startup. 112 | ; Note: Used only when pm is set to 'dynamic' 113 | ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 114 | pm.start_servers = 5 115 | 116 | ; The desired minimum number of idle server processes. 117 | ; Note: Used only when pm is set to 'dynamic' 118 | ; Note: Mandatory when pm is set to 'dynamic' 119 | pm.min_spare_servers = 5 120 | 121 | ; The desired maximum number of idle server processes. 122 | ; Note: Used only when pm is set to 'dynamic' 123 | ; Note: Mandatory when pm is set to 'dynamic' 124 | pm.max_spare_servers = 15 125 | 126 | ; The number of seconds after which an idle process will be killed. 127 | ; Note: Used only when pm is set to 'ondemand' 128 | ; Default Value: 10s 129 | ;pm.process_idle_timeout = 10s; 130 | 131 | ; The number of requests each child process should execute before respawning. 132 | ; This can be useful to work around memory leaks in 3rd party libraries. For 133 | ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. 134 | ; Default Value: 0 135 | ;pm.max_requests = 500 136 | 137 | ; The URI to view the FPM status page. If this value is not set, no URI will be 138 | ; recognized as a status page. It shows the following informations: 139 | ; pool - the name of the pool; 140 | ; process manager - static, dynamic or ondemand; 141 | ; start time - the date and time FPM has started; 142 | ; start since - number of seconds since FPM has started; 143 | ; accepted conn - the number of request accepted by the pool; 144 | ; listen queue - the number of request in the queue of pending 145 | ; connections (see backlog in listen(2)); 146 | ; max listen queue - the maximum number of requests in the queue 147 | ; of pending connections since FPM has started; 148 | ; listen queue len - the size of the socket queue of pending connections; 149 | ; idle processes - the number of idle processes; 150 | ; active processes - the number of active processes; 151 | 152 | ; total processes - the number of idle + active processes; 153 | ; max active processes - the maximum number of active processes since FPM 154 | ; has started; 155 | ; max children reached - number of times, the process limit has been reached, 156 | ; when pm tries to start more children (works only for 157 | ; pm 'dynamic' and 'ondemand'); 158 | ; Value are updated in real time. 159 | ; Example output: 160 | ; pool: www 161 | ; process manager: static 162 | ; start time: 01/Jul/2011:17:53:49 +0200 163 | ; start since: 62636 164 | ; accepted conn: 190460 165 | ; listen queue: 0 166 | ; max listen queue: 1 167 | ; listen queue len: 42 168 | ; idle processes: 4 169 | ; active processes: 11 170 | ; total processes: 15 171 | ; max active processes: 12 172 | ; max children reached: 0 173 | ; 174 | ; By default the status page output is formatted as text/plain. Passing either 175 | ; 'html', 'xml' or 'json' in the query string will return the corresponding 176 | ; output syntax. Example: 177 | ; http://www.foo.bar/status 178 | ; http://www.foo.bar/status?json 179 | ; http://www.foo.bar/status?html 180 | ; http://www.foo.bar/status?xml 181 | ; 182 | ; By default the status page only outputs short status. Passing 'full' in the 183 | ; query string will also return status for each pool process. 184 | ; Example: 185 | ; http://www.foo.bar/status?full 186 | ; http://www.foo.bar/status?json&full 187 | ; http://www.foo.bar/status?html&full 188 | ; http://www.foo.bar/status?xml&full 189 | ; The Full status returns for each process: 190 | ; pid - the PID of the process; 191 | ; state - the state of the process (Idle, Running, ...); 192 | ; start time - the date and time the process has started; 193 | ; start since - the number of seconds since the process has started; 194 | ; requests - the number of requests the process has served; 195 | ; request duration - the duration in µs of the requests; 196 | ; request method - the request method (GET, POST, ...); 197 | ; request URI - the request URI with the query string; 198 | ; content length - the content length of the request (only with POST); 199 | ; user - the user (PHP_AUTH_USER) (or '-' if not set); 200 | ; script - the main script called (or '-' if not set); 201 | ; last request cpu - the %cpu the last request consumed 202 | ; it's always 0 if the process is not in Idle state 203 | ; because CPU calculation is done when the request 204 | 205 | ; processing has terminated; 206 | ; last request memory - the max amount of memory the last request consumed 207 | ; it's always 0 if the process is not in Idle state 208 | ; because memory calculation is done when the request 209 | ; processing has terminated; 210 | ; If the process is in Idle state, then informations are related to the 211 | ; last request the process has served. Otherwise informations are related to 212 | ; the current request being served. 213 | ; Example output: 214 | ; ************************ 215 | ; pid: 31330 216 | ; state: Running 217 | ; start time: 01/Jul/2011:17:53:49 +0200 218 | ; start since: 63087 219 | ; requests: 12808 220 | ; request duration: 1250261 221 | ; request method: GET 222 | ; request URI: /test_mem.php?N=10000 223 | ; content length: 0 224 | ; user: - 225 | ; script: /home/fat/web/docs/php/test_mem.php 226 | ; last request cpu: 0.00 227 | ; last request memory: 0 228 | ; 229 | ; Note: There is a real-time FPM status monitoring sample web page available 230 | ; It's available in: @EXPANDED_DATADIR@/fpm/status.html 231 | ; 232 | ; Note: The value must start with a leading slash (/). The value can be 233 | ; anything, but it may not be a good idea to use the .php extension or it 234 | ; may conflict with a real PHP file. 235 | ; Default Value: not set 236 | ;pm.status_path = /status 237 | 238 | ; The ping URI to call the monitoring page of FPM. If this value is not set, no 239 | ; URI will be recognized as a ping page. This could be used to test from outside 240 | ; that FPM is alive and responding, or to 241 | ; - create a graph of FPM availability (rrd or such); 242 | ; - remove a server from a group if it is not responding (load balancing); 243 | ; - trigger alerts for the operating team (24/7). 244 | ; Note: The value must start with a leading slash (/). The value can be 245 | ; anything, but it may not be a good idea to use the .php extension or it 246 | ; may conflict with a real PHP file. 247 | ; Default Value: not set 248 | ;ping.path = /ping 249 | 250 | ; This directive may be used to customize the response of a ping request. The 251 | ; response is formatted as text/plain with a 200 response code. 252 | ; Default Value: pong 253 | ;ping.response = pong 254 | 255 | ; The access log file 256 | ; Default: not set 257 | ;access.log = log/$pool.access.log 258 | 259 | ; The access log format. 260 | ; The following syntax is allowed 261 | ; %%: the '%' character 262 | ; %C: %CPU used by the request 263 | ; it can accept the following format: 264 | ; - %{user}C for user CPU only 265 | ; - %{system}C for system CPU only 266 | ; - %{total}C for user + system CPU (default) 267 | ; %d: time taken to serve the request 268 | ; it can accept the following format: 269 | ; - %{seconds}d (default) 270 | ; - %{miliseconds}d 271 | ; - %{mili}d 272 | ; - %{microseconds}d 273 | ; - %{micro}d 274 | ; %e: an environment variable (same as $_ENV or $_SERVER) 275 | ; it must be associated with embraces to specify the name of the env 276 | ; variable. Some exemples: 277 | ; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e 278 | ; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e 279 | ; %f: script filename 280 | ; %l: content-length of the request (for POST request only) 281 | ; %m: request method 282 | ; %M: peak of memory allocated by PHP 283 | ; it can accept the following format: 284 | ; - %{bytes}M (default) 285 | ; - %{kilobytes}M 286 | ; - %{kilo}M 287 | ; - %{megabytes}M 288 | ; - %{mega}M 289 | ; %n: pool name 290 | ; %o: output header 291 | ; it must be associated with embraces to specify the name of the header: 292 | ; - %{Content-Type}o 293 | ; - %{X-Powered-By}o 294 | ; - %{Transfert-Encoding}o 295 | ; - .... 296 | ; %p: PID of the child that serviced the request 297 | ; %P: PID of the parent of the child that serviced the request 298 | ; %q: the query string 299 | ; %Q: the '?' character if query string exists 300 | ; %r: the request URI (without the query string, see %q and %Q) 301 | ; %R: remote IP address 302 | ; %s: status (response code) 303 | ; %t: server time the request was received 304 | ; it can accept a strftime(3) format: 305 | ; %d/%b/%Y:%H:%M:%S %z (default) 306 | ; The strftime(3) format must be encapsuled in a %{}t tag 307 | ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t 308 | ; %T: time the log has been written (the request has finished) 309 | ; it can accept a strftime(3) format: 310 | ; %d/%b/%Y:%H:%M:%S %z (default) 311 | ; The strftime(3) format must be encapsuled in a %{}t tag 312 | ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t 313 | ; %u: remote user 314 | ; 315 | ; Default: "%R - %u %t \"%m %r\" %s" 316 | ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" 317 | 318 | ; The log file for slow requests 319 | ; Default Value: not set 320 | ; Note: slowlog is mandatory if request_slowlog_timeout is set 321 | ;slowlog = /var/log/php-fpm/www-slow.log 322 | 323 | ; The timeout for serving a single request after which a PHP backtrace will be 324 | ; dumped to the 'slowlog' file. A value of '0s' means 'off'. 325 | ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) 326 | ; Default Value: 0 327 | ;request_slowlog_timeout = 0 328 | 329 | ; The timeout for serving a single request after which the worker process will 330 | ; be killed. This option should be used when the 'max_execution_time' ini option 331 | ; does not stop script execution for some reason. A value of '0' means 'off'. 332 | ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) 333 | ; Default Value: 0 334 | ;request_terminate_timeout = 0 335 | 336 | ; Set open file descriptor rlimit. 337 | ; Default Value: system defined value 338 | ;rlimit_files = 1024 339 | 340 | ; Set max core size rlimit. 341 | ; Possible Values: 'unlimited' or an integer greater or equal to 0 342 | ; Default Value: system defined value 343 | ;rlimit_core = 0 344 | 345 | ; Chroot to this directory at the start. This value must be defined as an 346 | ; absolute path. When this value is not set, chroot is not used. 347 | ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one 348 | ; of its subdirectories. If the pool prefix is not set, the global prefix 349 | ; will be used instead. 350 | ; Note: chrooting is a great security feature and should be used whenever 351 | ; possible. However, all PHP paths will be relative to the chroot 352 | ; (error_log, sessions.save_path, ...). 353 | ; Default Value: not set 354 | ;chroot = 355 | 356 | ; Chdir to this directory at the start. 357 | ; Note: relative path can be used. 358 | ; Default Value: current directory or / when chroot 359 | ;chdir = /var/www 360 | 361 | ; Redirect worker stdout and stderr into main error log. If not set, stdout and 362 | ; stderr will be redirected to /dev/null according to FastCGI specs. 363 | ; Note: on highloaded environement, this can cause some delay in the page 364 | ; process time (several ms). 365 | ; Default Value: no 366 | ;catch_workers_output = yes 367 | 368 | ; Clear environment in FPM workers 369 | ; Prevents arbitrary environment variables from reaching FPM worker processes 370 | ; by clearing the environment in workers before env vars specified in this 371 | ; pool configuration are added. 372 | ; Setting to "no" will make all environment variables available to PHP code 373 | ; via getenv(), $_ENV and $_SERVER. 374 | ; Default Value: yes 375 | ;clear_env = no 376 | 377 | ; Limits the extensions of the main script FPM will allow to parse. This can 378 | ; prevent configuration mistakes on the web server side. You should only limit 379 | ; FPM to .php extensions to prevent malicious users to use other extensions to 380 | ; exectute php code. 381 | ; Note: set an empty value to allow all extensions. 382 | ; Default Value: .php 383 | ;security.limit_extensions = .php .php3 .php4 .php5 .php7 384 | 385 | ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from 386 | ; the current environment. 387 | ; Default Value: clean env 388 | ;env[HOSTNAME] = $HOSTNAME 389 | ;env[PATH] = /usr/local/bin:/usr/bin:/bin 390 | ;env[TMP] = /tmp 391 | ;env[TMPDIR] = /tmp 392 | ;env[TEMP] = /tmp 393 | 394 | ; Additional php.ini defines, specific to this pool of workers. These settings 395 | ; overwrite the values previously defined in the php.ini. The directives are the 396 | ; same as the PHP SAPI: 397 | ; php_value/php_flag - you can set classic ini defines which can 398 | ; be overwritten from PHP call 'ini_set'. 399 | ; php_admin_value/php_admin_flag - these directives won't be overwritten by 400 | ; PHP call 'ini_set' 401 | ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. 402 | 403 | ; Defining 'extension' will load the corresponding shared extension from 404 | ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not 405 | ; overwrite previously defined php.ini values, but will append the new value 406 | ; instead. 407 | 408 | ; Note: path INI options can be relative and will be expanded with the prefix 409 | ; (pool, global or @prefix@) 410 | 411 | ; Default Value: nothing is defined by default except the values in php.ini and 412 | ; specified at startup with the -d argument 413 | ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com 414 | ;php_flag[display_errors] = off 415 | php_admin_value[error_log] = /var/log/php-fpm/7.1/www-error.log 416 | php_admin_flag[log_errors] = on 417 | ;php_admin_value[memory_limit] = 128M 418 | 419 | ; Set the following data paths to directories owned by the FPM process user. 420 | ; 421 | ; Do not change the ownership of existing system directories, if the process 422 | ; user does not have write permission, create dedicated directories for this 423 | ; purpose. 424 | ; 425 | ; See warning about choosing the location of these directories on your system 426 | ; at http://php.net/session.save-path 427 | php_value[session.save_handler] = files 428 | php_value[session.save_path] = /var/lib/php/7.1/session 429 | php_value[soap.wsdl_cache_dir] = /var/lib/php/7.1/wsdlcache 430 | 431 | ;php_value[opcache.file_cache] = /var/lib/php/7.1/opcache 432 | 433 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/appdeploy/enact/97_custom_logging.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xe 3 | 4 | if [ -f /etc/logrotate.d/nginx ] 5 | then 6 | /opt/elasticbeanstalk/bin/log-conf -n'nginx' -l'/var/log/nginx/*' -f /opt/elasticbeanstalk/support/conf/nginx.logrotate.conf 7 | rm -f /etc/logrotate.d/nginx 8 | fi 9 | 10 | if [ -f /etc/logrotate.d/php-fpm-7.1 ] 11 | then 12 | /opt/elasticbeanstalk/bin/log-conf -n'php-fpm' -l'/var/log/php-fpm/7.1/*log' -f /opt/elasticbeanstalk/support/conf/php-fpm.logrotate.conf 13 | rm -f /etc/logrotate.d/php-fpm-7.1 14 | fi 15 | 16 | if [ -d /etc/healthd -a ! -d /var/log/nginx/healthd ] 17 | then 18 | mkdir -p /var/log/nginx/healthd 19 | chown -R nginx:nginx /var/log/nginx/healthd 20 | fi 21 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/appdeploy/enact/98_nginx_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /opt/elasticbeanstalk/bin/get-config environment | python -c 'import json,sys;obj=json.load(sys.stdin);open("/etc/nginx/fastcgi_params_env", "wb").write("\n".join(["fastcgi_param %s %s;" % (key, obj[key]) for key in obj]));' 4 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/appdeploy/enact/99_reload_app_server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | service nginx restart 5 | service php-fpm restart 6 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/appdeploy/post/01_monitor_httpd_pid.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xe 4 | 5 | /opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy nginx 6 | /opt/elasticbeanstalk/bin/healthd-track-pidfile --name application --location /var/run/php-fpm/php-fpm-7.1.pid 7 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/appdeploy/post/02_restart_healthd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xe 4 | 5 | if [ -d /etc/healthd -a ! -f /var/elasticbeanstalk/healthd/current_proxy_server ] 6 | then 7 | /opt/elasticbeanstalk/bin/healthd-configure --appstat-log-path /var/log/nginx/healthd/application.log --appstat-unit sec --appstat-timestamp-on 'completion' 8 | /opt/elasticbeanstalk/bin/healthd-restart 9 | echo "nginx" > /var/elasticbeanstalk/healthd/current_proxy_server 10 | fi 11 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/configdeploy/enact/98_nginx_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /opt/elasticbeanstalk/bin/get-config environment | python -c 'import json,sys;obj=json.load(sys.stdin);open("/etc/nginx/fastcgi_params_env", "wb").write("\n".join(["fastcgi_param %s %s;" % (key, obj[key]) for key in obj]));' 4 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/configdeploy/enact/99_reload_app_server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | service nginx restart 5 | service php-fpm restart 6 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/restartappserver/enact/01_restart.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | service nginx restart 5 | service php-fpm restart 6 | -------------------------------------------------------------------------------- /.ebextensions/setup/hooks/restartappserver/pre/99_nginx_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /opt/elasticbeanstalk/bin/get-config environment | python -c 'import json,sys;obj=json.load(sys.stdin);open("/etc/nginx/fastcgi_params_env", "wb").write("\n".join(["fastcgi_param %s %s;" % (key, obj[key]) for key in obj]));' 4 | -------------------------------------------------------------------------------- /.ebextensions/setup/support/conf/nginx.logrotate.conf: -------------------------------------------------------------------------------- 1 | size 10M 2 | missingok 3 | notifempty 4 | rotate 5 5 | sharedscripts 6 | compress 7 | dateext 8 | dateformat -%s 9 | postrotate 10 | [ ! -f /var/run/nginx.pid ] || kill -USR1 $(cat /var/run/nginx.pid) || true 11 | endscript 12 | -------------------------------------------------------------------------------- /.ebextensions/setup/support/conf/php-fpm.logrotate.conf: -------------------------------------------------------------------------------- 1 | size 10M 2 | missingok 3 | notifempty 4 | rotate 5 5 | sharedscripts 6 | compress 7 | dateext 8 | dateformat -%s 9 | postrotate 10 | [ ! -f /var/run/php-fpm/php-fpm-7.1.pid ] || kill -USR1 $(cat /var/run/php-fpm/php-fpm-7.1.pid) || true 11 | endscript 12 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/bundlelogs.d/nginx.conf: -------------------------------------------------------------------------------- 1 | /var/log/nginx/* 2 | /var/log/nginx/rotated/* 3 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/bundlelogs.d/php-fpm.conf: -------------------------------------------------------------------------------- 1 | /var/log/php-fpm/7.1/* 2 | /var/log/php-fpm/7.1/rotated/* 3 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/publishlogs.d/nginx.conf: -------------------------------------------------------------------------------- 1 | /var/log/nginx/rotated/* 2 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/publishlogs.d/php-fpm.conf: -------------------------------------------------------------------------------- 1 | /var/log/php-fpm/7.1/rotated/* 2 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/systemtaillogs.d/nginx.conf: -------------------------------------------------------------------------------- 1 | /var/log/nginx/* 2 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/systemtaillogs.d/php-fpm.conf: -------------------------------------------------------------------------------- 1 | /var/log/php-fpm/7.1/* 2 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/taillogs.d/nginx.conf: -------------------------------------------------------------------------------- 1 | /var/log/nginx/* 2 | -------------------------------------------------------------------------------- /.ebextensions/setup/tasks/taillogs.d/php-fpm.conf: -------------------------------------------------------------------------------- 1 | /var/log/php-fpm/7.1/* 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 2 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Intellij ### 2 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 3 | 4 | *.iml 5 | .idea/ 6 | 7 | ### VisualStudioCode ### 8 | .vscode/* 9 | !.vscode/settings.json 10 | !.vscode/tasks.json 11 | !.vscode/launch.json 12 | 13 | ### SublimeText ### 14 | *.tmlanguage.cache 15 | *.tmPreferences.cache 16 | *.stTheme.cache 17 | *.sublime-workspace 18 | 19 | ### macOS ### 20 | *.DS_Store 21 | .AppleDouble 22 | .LSOverride 23 | 24 | ### Windows ### 25 | Thumbs.db 26 | ehthumbs.db 27 | 28 | ### Linux ### 29 | .Trash-* 30 | 31 | ### App Specific ### 32 | 33 | 34 | # Elastic Beanstalk Files 35 | .elasticbeanstalk/* 36 | !.elasticbeanstalk/*.cfg.yml 37 | !.elasticbeanstalk/*.global.yml 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | deploy: 2 | provider: elasticbeanstalk 3 | access_key_id: 4 | secret_access_key: 5 | secure: "Encypted =" 6 | region: "us-east-1" 7 | app: "example-app-name" 8 | env: "example-app-environment" 9 | bucket_name: "the-target-S3-bucket" 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rick Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Replace Apache with Nginx and PHP-FPM on AWS Beanstalk 2 | 3 | If you find yourself wanting to use Nginx and PHP-FPM instead of apache for your AWS Beanstalk PHP App, well good for you! 4 | 5 | This is a sample deployment with all of the .ebextensions to do so without having to make a custom AMI 6 | 7 | ## What's accomplished here? 8 | 9 | 1. Install nginx 10 | 2. Stop apache and keep it from starting up again 11 | 3. Make sure nginx and phpfpm start on reboot 12 | 4. Make sure environment variables are updated on both a configuration and app deployment 13 | 14 | ## How do I use it? 15 | 16 | You can pull down this repo, zip up the contents, making sure you include the .ebextensions directory and deploy to your 17 | beanlstalk application. Once the deployment has finished you should be able to hit your beanstalk ip and get the hello 18 | world response. 19 | 20 | ## Environment variables 21 | Environment variables are set in the /etc/nginx/fastcgi_params_env file and you can include them in your server block. 22 | You'll see an example of this in the default. This file will get updated with any environment variable changes on both 23 | application and config deployments. 24 | 25 | You can get environment variables in your php script with: 26 | 27 | `getenv('ENV_VARIABLE_NAME)` 28 | 29 | ## Nginx and PHPFPM config changes 30 | 31 | You'll find the base config files within the .ebextensions directory. You can modify as needed and they will take effect 32 | when you deploy. 33 | 34 | ## Why not create a custom AMI? 35 | 36 | You can go this route, but then in a few months when you want to use the latest version of amazon linux you'll need to 37 | completely recreate your custom AMI all over again. That gets to be a pain over the course of time. So, why not just 38 | stick with the default AMI and handle all of your setup via .ebextensions? 39 | 40 | ## I don't understand what's happening when I deploy? 41 | 42 | Take a look at the .ebextensions/01_setup.config file. I've commented each step. Things in the "commands" section 43 | happen early in the deployment process before your actual code is setup. 44 | 45 | ## Why not just get rid of apache completely? 46 | This ends up being a complete pain. Beanstalk has many commands baked in with apache, so it just gets troublesome to 47 | get them all. So instead we keep apache in place but just tell Elasticbeanstalk to disable it. 48 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 |