Last active
December 14, 2015 19:19
-
-
Save hendrauzia/5135852 to your computer and use it in GitHub Desktop.
Ubuntu Server 12.04 LTS with NGINX + PHP-FPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# upgrade the server | |
locale-gen UTF-8 | |
apt-get update | |
apt-get dist-upgrade | |
reboot | |
# install nginx | |
add-apt-repository ppa:nginx/stable | |
apt-get upgrade | |
apt-get install nginx | |
# install php | |
apt-get install php5 php5-fpm php5-mysql | |
# install subversion | |
apt-get install subversion | |
# add user for nginx | |
adduser --system --no-create-home nginx | |
# configure nginx.conf | |
tee -a /etc/nginx/sites-available/DOMAINNAME <<EOF | |
# rewrite www to DOMAINNAME | |
server { | |
server_name www.DOMAINNAME; | |
rewrite ^(.*) http://DOMAINNAME$1 permanent; | |
} | |
server { | |
listen [::]:80 ipv6only=on; | |
listen 80; | |
server_name DOMAINNAME; | |
root /var/apps/APPNAME; | |
index index.php; | |
# Logging | |
access_log /var/log/nginx/DOMAINNAME.access.log; | |
error_log /var/log/nginx/DOMAINNAME.error.log notice; | |
# serve static files directly | |
location ~* \.(css|js|jpeg|jpg|gif|png|ico|xml)$ { | |
access_log off; | |
expires 30d; | |
} | |
# do not log robots and favicon | |
location ~* ^/(favicon.ico|robots.txt)$ { | |
access_log off; | |
log_not_found off; | |
} | |
# restrict access to htaccess files | |
location ~ /\.ht { | |
deny all; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.php$ { | |
fastcgi_pass unix:/var/run/php5-fpm/DOMAINNAME.socket; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/apps/APPNAME$fastcgi_script_name; | |
fastcgi_buffers 128 8k; | |
include /etc/nginx/fastcgi_params; | |
} | |
} | |
EOF | |
ln -s /etc/nginx/sites-available/DOMAINNAME /etc/nginx/sites-enabled/DOMAINNAME | |
# configure php-fpm | |
mkdir -p /var/run/php5-fpm/ | |
tee -a /etc/php5/fpm/pool.d/DOMAINNAME.conf <<EOF | |
[DOMAINNAME] | |
listen = /var/run/php5-fpm/DOMAINNAME.socket | |
listen.backlog = -1 | |
; Unix user/group of processes | |
user = APPUSER | |
group = www-data | |
; Choose how the process manager will control the number of child processes. | |
pm = dynamic | |
pm.max_children = 75 | |
pm.start_servers = 10 | |
pm.min_spare_servers = 5 | |
pm.max_spare_servers = 20 | |
pm.max_requests = 500 | |
; Pass environment variables | |
env[HOSTNAME] = $HOSTNAME | |
env[PATH] = /usr/local/bin:/usr/bin:/bin | |
env[TMP] = /tmp | |
env[TMPDIR] = /tmp | |
env[TEMP] = /tmp | |
pm.start_servers = 10 | |
pm.min_spare_servers = 5 | |
pm.max_spare_servers = 20 | |
pm.max_requests = 500 | |
; Pass environment variables | |
env[HOSTNAME] = $HOSTNAME | |
env[PATH] = /usr/local/bin:/usr/bin:/bin | |
env[TMP] = /tmp | |
env[TMPDIR] = /tmp | |
env[TEMP] = /tmp | |
; host-specific php ini settings here | |
php_value[short_open_tag] = On | |
EOF | |
# create application folder | |
cd /var/apps | |
sudo adduser --system --no-create-home --ingroup www-data --disabled-password --disabled-login APPUSER | |
svn checkout https://[email protected]/repo/branches/master APPNAME | |
chown APPUSER:www-data APPNAME | |
# run the server | |
service nginx start | |
service php-fpm start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment