├── .gitignore ├── README.md └── .ebextensions └── 01_nginx_php_fpm.config /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is the sample config of .ebextensions to setup an Elastic Beanstalk PHP 5.4 container using Nginx and PHP-FPM 4 | 5 | 6 | Using the non-legacy containers allows you to use Nginx (or any other services that you would like to) without the need of building a customised AMI. 7 | 8 | Tested on ami-1624987f, PHP 5.4 default. Could work with others. 9 | 10 | 11 | Many thanks to https://github.com/carboncoders/elasticbeanstalk-nginx-php for the base config of Nginx and PHP-FPM 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.ebextensions/01_nginx_php_fpm.config: -------------------------------------------------------------------------------- 1 | packages: 2 | yum: 3 | nginx: [] 4 | php54-fpm: [] 5 | 6 | files: 7 | "/opt/elasticbeanstalk/hooks/appdeploy/enact/99_reload_app_server.sh" : 8 | mode: "000777" 9 | owner: root 10 | group: root 11 | content: | 12 | #!/usr/bin/env bash 13 | . /opt/elasticbeanstalk/support/envvars 14 | service httpd stop 15 | service nginx restart 16 | service php-fpm restart 17 | 18 | files: 19 | "/etc/nginx/nginx.conf" : 20 | mode: "000644" 21 | owner: root 22 | group: root 23 | content: | 24 | user webapp; # Needed for permissions 25 | pid /var/run/nginx.pid; 26 | worker_processes 4; # Match number of cores 27 | worker_rlimit_nofile 200000; 28 | 29 | error_log /var/log/nginx/nginx-error.log error; 30 | 31 | events { 32 | worker_connections 19000; 33 | use epoll; 34 | multi_accept on; 35 | } 36 | 37 | http { 38 | access_log off; 39 | 40 | open_file_cache max=200000 inactive=20s; 41 | open_file_cache_valid 30s; 42 | open_file_cache_min_uses 2; 43 | open_file_cache_errors on; 44 | 45 | keepalive_timeout 5 5; 46 | keepalive_requests 100000; 47 | reset_timedout_connection on; 48 | client_body_timeout 10; 49 | send_timeout 10; 50 | 51 | port_in_redirect off; 52 | server_tokens off; # Remove version info 53 | tcp_nodelay on; 54 | tcp_nopush on; 55 | sendfile on; 56 | 57 | gzip on; 58 | gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; 59 | gzip_comp_level 6; 60 | gzip_proxied any; 61 | gzip_vary on; 62 | 63 | include /etc/nginx/conf.d/*.conf; 64 | include mime.types; 65 | } 66 | 67 | "/etc/nginx/conf.d/webapp.conf" : 68 | mode: "000644" 69 | owner: root 70 | group: root 71 | content: | 72 | server { 73 | listen 80; 74 | server_name _; 75 | root /var/www/html; 76 | index index.php index.html index.htm; 77 | 78 | # No logs, to avoid filling the instance disk 79 | log_not_found off; 80 | access_log off; 81 | 82 | # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 83 | location ~ /\. { 84 | deny all; 85 | } 86 | 87 | # Example of "mod_rewrite" for use with a framework or wordpress or others. 88 | location / { 89 | try_files $uri $uri/ /index.php?$args; 90 | } 91 | 92 | # Tell browser to cache image files for 24 hours, do not log missing images 93 | # I typically keep this after the yii rules, so that there is no conflict with content served by Yii 94 | location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 95 | expires 24h; 96 | } 97 | 98 | # Block for processing PHP files 99 | # Specifically matches URIs ending in .php 100 | location ~ \.php$ { 101 | try_files $uri =404; 102 | 103 | # Fix for server variables that behave differently under nginx/php-fpm than typically expected 104 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 105 | # Include the standard fastcgi_params file included with nginx 106 | include fastcgi_params; 107 | fastcgi_param PATH_INFO $fastcgi_path_info; 108 | fastcgi_index index.php; 109 | # Override the SCRIPT_FILENAME variable set by fastcgi_params 110 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 111 | # Pass to upstream PHP-FPM; This must match whatever you name your upstream connection 112 | fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # Using socket, faster 113 | } 114 | } 115 | 116 | "/etc/php-fpm.d/www.conf" : 117 | mode: "000644" 118 | owner: root 119 | group: root 120 | content: | 121 | [www] 122 | listen = /var/run/php-fpm/php-fpm.sock 123 | listen.allowed_clients = 127.0.0.1 124 | 125 | ; Need to set owner/group for valid permissions 126 | listen.owner = webapp 127 | listen.group = webapp 128 | user = webapp 129 | group = webapp 130 | 131 | ; Child processes 132 | pm = dynamic 133 | pm.max_children = 5 134 | pm.start_servers = 3 135 | pm.min_spare_servers = 2 136 | pm.max_spare_servers = 4 137 | pm.max_requests = 200 138 | 139 | ; Timeouts 140 | request_terminate_timeout = 120s 141 | request_slowlog_timeout = 5s 142 | slowlog = /var/log/nginx/fpm-slow.log 143 | 144 | ; Environment variables 145 | env[HOSTNAME] = $HOSTNAME 146 | env[TMP] = /tmp 147 | env[TMPDIR] = /tmp 148 | env[TEMP] = /tmp 149 | 150 | ; PHP settings 151 | php_admin_value[error_log] = /var/log/nginx/php-error.log 152 | php_admin_flag[log_errors] = on 153 | 154 | #TODO: Make Dynamic config about GZIP using enviroment 155 | #TODO: Make dynaic config about server root using EB_CONFIG_DOCUMENT_ROOT --------------------------------------------------------------------------------