Last active
March 8, 2017 09:45
-
-
Save anhtuank7c/74d404b63ebb33ce17973d079b84aed1 to your computer and use it in GitHub Desktop.
Install nginx, openssl, google pagespeed, php7.0, mysql 5.7, phpmyadmin, cakephp 3.x on ubuntu 14.04 with default account "ubuntu". If your server don't have ubuntu account, please replace ubuntu by your account. Download this script to your server then "chmod +x install_nginx_php7.sh". Execute script by "./install_nginx_php7.sh"
This file contains hidden or 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
#!/bin/bash | |
## Author: Anh Tuan Nguyen ([email protected]) | |
## Created: 08/08/2016 | |
## Install nginx, openssl, php7.0, mysql 5.7, phpmyadmin, cakephp 3.x | |
# update, upgrade to latest source | |
sudo apt-get update -y | |
sudo apt-get upgrade -y | |
# GOOGLE PAGE SPEED | |
sudo apt-get install -y build-essential zlib1g-dev libpcre3 libpcre3-dev unzip | |
# download ngx_pagespeed | |
cd | |
NPS_VERSION=1.11.33.2 | |
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip -O release-${NPS_VERSION}-beta.zip | |
unzip release-${NPS_VERSION}-beta.zip | |
cd ngx_pagespeed-release-${NPS_VERSION}-beta/ | |
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz | |
tar -xzvf ${NPS_VERSION}.tar.gz # extracts to psol/ | |
# download openssl | |
cd | |
OPENSSL_VERSION=1.0.2h | |
wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz | |
tar -xf openssl-${OPENSSL_VERSION}.tar.gz | |
# Download and build nginx with support for pagespeed | |
cd | |
# check http://nginx.org/en/download.html for the latest version | |
NGINX_VERSION=1.10.1 | |
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | |
tar -xvzf nginx-${NGINX_VERSION}.tar.gz | |
cd nginx-${NGINX_VERSION}/ | |
./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta ${PS_NGX_EXTRA_FLAGS} --with-http_ssl_module --with-openssl=/home/ubuntu/openssl-${OPENSSL_VERSION} | |
make | |
sudo make install | |
# CREATE START/STOP/RELOAD script | |
sudo 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' > /home/ubuntu/nginx | |
sudo mv /home/ubuntu/nginx /etc/init.d/nginx | |
sudo chown root:root /etc/init.d/nginx | |
sudo chmod 0755 /etc/init.d/nginx | |
sudo service nginx start | |
# PHP55-fpm | |
sudo add-apt-repository ppa:ondrej/php | |
sudo apt-get update | |
sudo apt-get install -y php7.0-common php7.0-fpm php7.0-mysql php7.0-sqlite php7.0-curl php7.0-gd php7.0-cli php7.0-intl php7.0-apcu php7.0-mbstring curl php7.0-cli php7.0-xml php7.0-zip git | |
# Update php configs | |
sudo sed -i "s/listen = \/run\/php\/php7.0-fpm.sock/listen = 127.0.0.1:9000/g" /etc/php/7.0/fpm/pool.d/www.conf # Use a port instead of a socket | |
sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/short_open_tag = Off/short_open_tag = On/g" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/session.gc_maxlifetime = 1440/session.gc_maxlifetime = 43200/g" /etc/php/7.0/fpm/php.ini # Update session timeout | |
# Remove default html folder, create config sites folder, projects folder | |
sudo rm -rf /usr/local/nginx/html | |
sudo mkdir -p /usr/local/nginx/projects | |
sudo mkdir -p /usr/local/nginx/sites-available | |
sudo mkdir -p /usr/local/nginx/sites-enabled | |
sudo chown -R www-data:www-data /usr/local/nginx/projects | |
sudo chown -R www-data:www-data /usr/local/nginx/logs | |
sudo chown -R www-data:www-data /usr/local/nginx/sites-available/ | |
sudo chown -R www-data:www-data /usr/local/nginx/sites-enabled/ | |
# add user ubuntu to www-data group, then allow all member in group www-data can rwx | |
sudo usermod -aG www-data ubuntu | |
sudo chmod -R g+rwx /usr/local/nginx/projects/ | |
sudo chmod -R g+rwx /usr/local/nginx/sites-available/ | |
sudo chmod -R g+rwx /usr/local/nginx/sites-enabled/ | |
# remove default nginx.conf | |
sudo rm -f /usr/local/nginx/conf/nginx.conf | |
# create new nginx.conf that allow vhost | |
sudo echo 'user www-data; | |
worker_processes auto; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
## | |
# Virtual Host Configs | |
## | |
include /usr/local/nginx/conf.d/*.conf; | |
include /usr/local/nginx/sites-enabled/*; | |
## | |
# Upload file Settings | |
## | |
client_body_in_file_only clean; | |
client_max_body_size 5M; | |
client_body_buffer_size 128k; | |
## | |
# Symlink | |
## | |
disable_symlinks off; | |
}' > /home/ubuntu/nginx.conf | |
sudo mv /home/ubuntu/nginx.conf /usr/local/nginx/conf/ | |
sudo chown root:root /usr/local/nginx/conf/nginx.conf | |
sudo chmod 0644 /usr/local/nginx/conf/nginx.conf | |
# allow user in group www-data can wrx | |
sudo chmod -R u+wrx /usr/local/nginx/sites-available/ | |
sudo chmod -R u+wrx /usr/local/nginx/sites-enabled/ | |
sudo chmod -R u+wrx /usr/local/nginx/projects/ | |
# restart php7.0-fpm, nginx | |
sudo service php7.0-fpm restart | |
sudo service nginx restart | |
# Start nginx on boot | |
sudo update-rc.d nginx defaults | |
# install demo cakephp project | |
while true; do | |
read -p $'Do you wish to create demo cakephp 3.x project? (y/n)\n' yn | |
case $yn in | |
[Yy]* ) | |
# Create vhost demo | |
sudo echo 'server { | |
listen 80; | |
server_name localhost; | |
# Google pagespeed | |
pagespeed on; | |
pagespeed FileCachePath /var/ngx_pagespeed_cache; | |
pagespeed CriticalImagesBeaconEnabled false; | |
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { | |
add_header "" ""; | |
} | |
location ~ "^/pagespeed_static/" { } | |
location ~ "^/ngx_pagespeed_beacon$" { } | |
root projects/demo/webroot/; | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri /index.php?$args; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
#error_page 500 502 503 504 /50x.html; | |
#location = /50x.html { | |
# root projects/demo/webroot/; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
}' > /home/ubuntu/demo | |
sudo mv /home/ubuntu/demo /usr/local/nginx/sites-available/ | |
sudo ln -s /usr/local/nginx/sites-available/demo /usr/local/nginx/sites-enabled/demo | |
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer | |
sudo composer create-project --prefer-dist cakephp/app /usr/local/nginx/projects/demo | |
break;; | |
[Nn]* ) | |
sudo mkdir -p /usr/local/nginx/projects/demo | |
sudo echo '<?php phpinfo();?>' > /usr/local/nginx/projects/demo/index.php | |
# Create vhost demo | |
sudo echo 'server { | |
listen 80; | |
server_name localhost; | |
# Google pagespeed | |
pagespeed on; | |
pagespeed FileCachePath /var/ngx_pagespeed_cache; | |
pagespeed CriticalImagesBeaconEnabled false; | |
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { | |
add_header "" ""; | |
} | |
location ~ "^/pagespeed_static/" { } | |
location ~ "^/ngx_pagespeed_beacon$" { } | |
root projects/demo/; | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri /index.php?$args; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
#error_page 500 502 503 504 /50x.html; | |
#location = /50x.html { | |
# root projects/demo/; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
}' > /home/ubuntu/demo | |
sudo mv /home/ubuntu/demo /usr/local/nginx/sites-available/ | |
sudo chown -R www-data:www-data /usr/local/nginx/projects | |
sudo ln -s /usr/local/nginx/sites-available/demo /usr/local/nginx/sites-enabled | |
echo $'You choose No. Go to next statement' | |
break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
# install mysql 5.7 | |
while true; do | |
read -p $'Do you wish to install mysql-server 5.7? (y/n)\n' yn | |
case $yn in | |
[Yy]* ) | |
cd | |
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb | |
echo $'Please choose mysql-server version 5.7 then choose ok\n' | |
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb | |
sudo apt-get update | |
sudo apt-get install -y mysql-server | |
sudo mysql_secure_installation | |
mysql --version | |
service mysql status | |
break;; | |
[Nn]* ) | |
echo $'You choose No. Go to next statement' | |
break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
# install phpmyadmin | |
while true; do | |
read -p $'Do you wish to install phpmyadmin? (y/n)\n' yn | |
case $yn in | |
[Yy]* ) | |
# Create vhost demo | |
sudo echo 'server { | |
listen 80; | |
server_name localhost; | |
# Google pagespeed | |
pagespeed on; | |
pagespeed FileCachePath /var/ngx_pagespeed_cache; | |
pagespeed CriticalImagesBeaconEnabled false; | |
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { | |
add_header "" ""; | |
} | |
location ~ "^/pagespeed_static/" { } | |
location ~ "^/ngx_pagespeed_beacon$" { } | |
root projects/phpmyadmin/; | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri /index.php?$args; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
#error_page 500 502 503 504 /50x.html; | |
#location = /50x.html { | |
# root projects/phpmyadmin/; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
}' > /home/ubuntu/phpmyadmin | |
sudo mv /home/ubuntu/phpmyadmin /usr/local/nginx/sites-available/ | |
sudo ln -s /usr/local/nginx/sites-available/phpmyadmin /usr/local/nginx/sites-enabled | |
sudo git clone --depth=1 --branch=STABLE https://github.com/phpmyadmin/phpmyadmin.git /usr/local/nginx/projects/phpmyadmin | |
sudo service php7.0-fpm restart | |
break;; | |
[Nn]* ) | |
echo $'Finished.\nThank you' | |
break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment