Skip to content

Instantly share code, notes, and snippets.

@kengoldfarb
Last active January 8, 2019 20:17
Show Gist options
  • Save kengoldfarb/9517675 to your computer and use it in GitHub Desktop.
Save kengoldfarb/9517675 to your computer and use it in GitHub Desktop.
Nginx 1.6.0 - Pagespeed - PHP-FPM 5.5.x Installation
#!/bin/bash
## Author: Ken Goldfarb <[email protected]>
## https://github.com/kengoldfarb
##
## This script will install Nginx+Pagespeed with PHP-FPM 5.5.x
## It's testsed working on a stock AWS Ubuntu 14.04 image
##
## BONUS: Oh-my-zsh installation included!
# ZSH - Uncomment these lines to install Oh-My-ZSH (https://github.com/robbyrussell/oh-my-zsh)
#apt-get install zsh
#apt-get install git-core
#wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
#chsh -s `which zsh`
# PAGESPEED
apt-get install -y build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libgd2-xpm-dev libgeoip-dev libperl-dev unzip libxml2-dev libxslt-dev
cd ~
wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.9.32.2-beta.zip
unzip v1.9.32.2-beta.zip
cd ngx_pagespeed-1.9.32.2-beta/
wget https://dl.google.com/dl/page-speed/psol/1.9.32.2.tar.gz
tar -xzvf 1.9.32.2.tar.gz
# Echo Module
cd ~
wget https://github.com/openresty/echo-nginx-module/archive/v0.57.tar.gz
tar xzvf v0.57.tar.gz
cd ~
wget https://github.com/agentzh/headers-more-nginx-module/archive/v0.25.tar.gz
tar xzvf v0.25.tar.gz
cd ~
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar -xvzf nginx-1.6.2.tar.gz
cd nginx-1.6.2/
./configure --add-module=$HOME/ngx_pagespeed-1.9.32.2-beta --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_spdy_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=$HOME/headers-more-nginx-module-0.25 --add-module=$HOME/echo-nginx-module-0.57
make
make install
# Setup nginx dirs
mkdir -p /var/log/nginx
# Create startup script for nginx
echo '#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/share/nginx:/usr/share/nginx/sbin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0' > /etc/init.d/nginx
chmod 0755 /etc/init.d/nginx
service nginx start
# PHP55-fpm
apt-get install -y python-software-properties
add-apt-repository -y ppa:ondrej/php5
apt-get update
apt-get install -y php5-common php5-fpm php5-mysql php5-sqlite php5-curl php5-imagick php5-gd php5-cli
# Update php configs
sed -i "s/listen = \/var\/run\/php5-fpm.sock/listen = 127.0.0.1:9000/g" /etc/php5/fpm/pool.d/www.conf # Use a port instead of a socket
# sed -i "s/short_open_tag = Off/short_open_tag = On/g" /etc/php5/fpm/php.ini # Turn on PHP short tags
# sed -i "s/post_max_size = 3M/post_max_size = 250M/g" /etc/php5/fpm/php.ini # Change the php POST size
# sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 200M/g" /etc/php5/fpm/php.ini # Change the php max upload size
# sed -i "s/memory_limit = 128M/memory_limit = -1/g" /etc/php5/fpm/php.ini
# sed -i "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php5/fpm/php.ini
# sed -i "s/max_input_time = 60/max_input_time = 300/g" /etc/php5/fpm/php.ini
# sed -i "s/post_max_size = 8M/post_max_size = 300M/g" /etc/php5/fpm/php.ini
sed -i "s/session.gc_maxlifetime = 1440/session.gc_maxlifetime = 43200/g" /etc/php5/fpm/php.ini # Update session timeout
service php5-fpm restart
# Start nginx on boot
update-rc.d nginx defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment