Skip to content

Instantly share code, notes, and snippets.

@deepaknverma
Created October 20, 2014 01:13
Show Gist options
  • Save deepaknverma/3060b7b810c15c75c51b to your computer and use it in GitHub Desktop.
Save deepaknverma/3060b7b810c15c75c51b to your computer and use it in GitHub Desktop.
NGINX and PHP-FPM setup on AMAZON-EC2 for heavy lifting
--------------------------------------------
Install PHP 5.4.x
--------------------------------------------
yum install \
php54.x86_64 \
php54-bcmath.x86_64 \
php54-cli.x86_64 \
php54-common.x86_64 \
php54-dba.x86_64 \
php54-devel.x86_64 \
php54-fpm.x86_64 \
php54-gd.x86_64 \
php54-intl.x86_64 \
php54-mbstring.x86_64 \
php54-mcrypt.x86_64 \
php54-mysql.x86_64 \
php54-pdo.x86_64 \
php54-pecl-apc.x86_64 \
php54-process.x86_64 \
php54-xml.x86_64
--------------------------------------------
Install Nginx
--------------------------------------------
yum install nginx.x86_64
--------------------------------------------
Nginx configuration (/etc/nginx/nginx.conf)
--------------------------------------------
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 32768;
multi_accept on;
use epoll;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server {
listen 80;
server_name _;
root /your/local/web/app/root/;
index index.php index.htm index.html;
try_files $uri $uri/ $uri/index.php /index.php;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /your/local/web/app/root/$fastcgi_script_name;
fastcgi_param ENVIRONMENT production;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location / {
rewrite ^ /index.php last; # alike mod_rewrite, redirect uri to index.php
}
}
}
-------------------------------------------------------
Adjust PHP FPM configuration (/etc/php-fpm.d/www.conf)
-------------------------------------------------------
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
pm = static
pm.max_children = 64
--------------------------------------------
Linux sysctl tunning (/etc/sysctl.conf)
--------------------------------------------
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.core.somaxconn = 256000
net.core.netdev_max_backlog = 512000
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_congestion_control = cubic
nte.ipv4.tcp_max_syn_backlog = 256000
--------------------------------------------------
Linux limits tunning (/etc/security/limits.conf)
--------------------------------------------------
root hard nofile 40000
root soft nofile 40000
nginx hard nofile 40000
nginx soft nofile 40000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment