diff --git a/scripts/setup-web2py-nginx-uwsgi-centos7.sh b/scripts/setup-web2py-nginx-uwsgi-centos7.sh new file mode 100644 index 00000000..a6b62152 --- /dev/null +++ b/scripts/setup-web2py-nginx-uwsgi-centos7.sh @@ -0,0 +1,235 @@ +#!/bin/bash + +# This script will install web2py with nginx+uwsgi on centos 7 +# This script is based on excellent tutorial by Justin Ellingwood on +# https://www.digitalocean.com/community/tutorials/how-to-deploy-web2py-python-applications-with-uwsgi-and-nginx-on-centos-7 + +# +# Phase 1: First, let's ask a few things +# + +read -p "Enter username under which web2py will be installed [web2py]: " USERNAME +USERNAME=${USERNAME:-web2py} + +read -p "Enter path where web2py will be installed [/opt/web2py_apps]: " WEB2PY_PATH +WEB2PY_PATH=${WEB2PY_PATH:-/opt/web2py_apps} + +read -p "Web2py subdirectory will be called: [web2py]: " WEB2PY_APP +WEB2PY_APP=${WEB2PY_APP:-web2py} + +read -p "Enter your web2py admin password: " WEB2PY_PASS + +read -p "Enter your domain name: " YOUR_SERVER_DOMAIN + +# open new user +useradd -d $WEB2PY_PATH $USERNAME + +# if it's not already open, let's create a directory for web2py +mkdir -p $WEB2PY_PATH + +# now let's create a self signed certificate +cd $WEB2PY_PATH + +openssl req -x509 -new -newkey rsa:4096 -days 3652 -nodes -keyout $WEB2PY_APP.key -out $WEB2PY_APP.crt + +# +# phase 2: That was all the input that we needed so let's install the components +# + +echo "Installing necessary components" + +# Verify packages are up to date +yum -y upgrade + +# Install required packages +yum install -y epel-release +yum install -y python-devel python-pip gcc nginx wget unzip python-psycopg2 MySQL-python + +# download and unzip web2py + +echo "Downloading web2py" + +cd $WEB2PY_PATH +wget http://web2py.com/examples/static/web2py_src.zip +unzip web2py_src.zip +rm web2py_src.zip + +# preparing wsgihandler +chown -R $USERNAME.$USERNAME $WEB2PY_PATH/$WEB2PY_APP +mv $WEB2PY_PATH/$WEB2PY_APP/handlers/wsgihandler.py $WEB2PY_PATH/$WEB2PY_APP + +# now let's install uwsgi + +pip install uwsgi + +# preparing directories +mkdir -p /etc/uwsgi/sites +mkdir -p /var/log/uwsgi +mkdir -p /etc/nginx/ssl/ + +# +# Phase 3: Ok, everything is installed now so we'll configure things +# + +# Create configuration file for uwsgi in /etc/uwsgi/$WEB2PY_APP.ini +echo '[uwsgi] +chdir = WEB2PY_PATH_PLACEHOLDER/WEB2PY_APP_PLACEHOLDER +module = wsgihandler:application + +master = true +processes = 5 + +uid = USERNAME_PLACEHOLDER +socket = /run/uwsgi/WEB2PY_APP_PLACEHOLDER.sock +chown-socket = USERNAME_PLACEHOLDER:nginx +chmod-socket = 660 +vacuum = true +' >/etc/uwsgi/sites/$WEB2PY_APP.ini + +sed -i "s@WEB2PY_PATH_PLACEHOLDER@$WEB2PY_PATH@" /etc/uwsgi/sites/$WEB2PY_APP.ini +sed -i "s@WEB2PY_APP_PLACEHOLDER@$WEB2PY_APP@" /etc/uwsgi/sites/$WEB2PY_APP.ini +sed -i "s@USERNAME_PLACEHOLDER@$USERNAME@" /etc/uwsgi/sites/$WEB2PY_APP.ini + +# Create a daemon configuration file for uwsgi +cat > /etc/systemd/system/uwsgi.service < /etc/nginx/nginx.conf <