Skip to content

Instantly share code, notes, and snippets.

@tolemac
Forked from ikennaokpala/install.sh
Last active January 18, 2018 13:34
Show Gist options
  • Save tolemac/5847b820e6399880bb83ff6823b26e85 to your computer and use it in GitHub Desktop.
Save tolemac/5847b820e6399880bb83ff6823b26e85 to your computer and use it in GitHub Desktop.
install nginx with ngx_lua automatically under debian/ubuntu like system
#!/bin/bash
set -e
NGX_VER="1.12.2"
NDK_VER="0.3.0"
NGX_LUA_VER="0.10.11"
LUAJIT_VER="2.0.5"
LUAROCKS_VER="2.4.3"
WORKDIR=$(pwd)
NGX_INSTALL_DIR="/etc/nginx"
if ! [ -e "nginx-${NGX_VER}.tar.gz" ]; then
wget http://nginx.org/download/nginx-${NGX_VER}.tar.gz
fi
if ! [ -e "v${NDK_VER}.tar.gz" ]; then
wget https://github.com/simpl/ngx_devel_kit/archive/v${NDK_VER}.tar.gz
fi
if ! [ -e "v${NGX_LUA_VER}.tar.gz" ]; then
wget https://github.com/openresty/lua-nginx-module/archive/v${NGX_LUA_VER}.tar.gz
fi
if ! [ -e "LuaJIT-${LUAJIT_VER}.tar.gz" ]; then
wget http://luajit.org/download/LuaJIT-${LUAJIT_VER}.tar.gz
fi
if ! [ -e "luarocks-${LUAROCKS_VER}.tar.gz" ]; then
wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz
fi
install_luarocks() {
cd $WORKDIR
tar zxpf luarocks-${LUAROCKS_VER}.tar.gz
cd luarocks-${LUAROCKS_VER}
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0
sudo make bootstrap
}
extract_ndk() {
if ! [ -d ${WORKDIR}/ngx_devel_kit-${NDK_VER} ]; then
tar zxf v${NDK_VER}.tar.gz
fi
}
extract_lua_ngx() {
if ! [ -d ${WORKDIR}/lua-nginx-module-${NGX_LUA_VER} ]; then
tar zxf v${NGX_LUA_VER}.tar.gz
fi
}
install_luajit() {
cd $WORKDIR
tar zxf LuaJIT-${LUAJIT_VER}.tar.gz
cd LuaJIT-${LUAJIT_VER}
make
sudo make install
}
extract_nginx() {
if ! [ -d "$WORKDIR/nginx-${NGX_VER}" ]; then
tar zxf nginx-${NGX_VER}.tar.gz
fi
}
install_nginx() {
cd "$WORKDIR/nginx-${NGX_VER}"
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./configure --prefix=${NGX_INSTALL_DIR} --with-ld-opt='-Wl,-rpath,/usr/local/lib' --add-module=${WORKDIR}/ngx_devel_kit-${NDK_VER} --add-module=${WORKDIR}/lua-nginx-module-${NGX_LUA_VER}
make -j2
sudo make install
sudo ln -sf ${NGX_INSTALL_DIR}/sbin/nginx /usr/local/bin
}
sudo apt-get update
sudo apt-get install -yy build-essential make libpcre3-dev zlibc zlib1g-dev
extract_ndk
extract_nginx
extract_lua_ngx
if [ -z `command -v luajit` ]; then
install_luajit
fi
if [ -z `command -v nginx`]; then
install_nginx
fi
if [ -z `command -v luarocks` ]; then
install_luarocks
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment