Skip to content

Instantly share code, notes, and snippets.

@es
Last active August 21, 2016 06:20
Show Gist options
  • Save es/e44d93ee43b17afe825e1ab4178ddfd0 to your computer and use it in GitHub Desktop.
Save es/e44d93ee43b17afe825e1ab4178ddfd0 to your computer and use it in GitHub Desktop.
Openresty Development Environment
#!/bin/sh
export JOBS=3
export DEBIAN_FRONTEND=noninteractive
export PERL_MM_USE_DEFAULT=1
export CC=gcc
sudo apt-get update
sudo -E apt-get -y install vim \
curl \
perl \
make \
build-essential \
procps \
build-essential \
libreadline-dev \
libncurses5-dev \
libpcre3-dev \
libssl-dev \
mysql-server \
memcached \
redis-server \
dos2unix \
git \
axel \
cpanminus \
libtest-base-perl \
libtext-diff-perl \
liburi-perl \
libwww-perl \
libtest-longstring-perl \
liblist-moreutils-perl \
libgd-dev
mysql -uroot -e 'create database ngx_test; grant all on ngx_test.* to "ngx_test"@"%" identified by "ngx_test"; flush privileges;'
# Install LuaJIT
export LUA_JIT_VERSION=2.1.0-beta2
export LUAJIT_PREFIX=/opt/luajit21
export LUAJIT_LIB=$LUAJIT_PREFIX/lib
export LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
export LUA_INCLUDE_DIR=$LUAJIT_INC
export LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
cd $HOME
git clone -b v2.1-agentzh https://github.com/openresty/luajit2
cd luajit2
make PREFIX=$LUAJIT_PREFIX -j$JOBS && sudo make PREFIX=$LUAJIT_PREFIX install
# Download OpenResty libraries
cd $HOME
git clone https://github.com/openresty/openresty.git openresty
git clone https://github.com/openresty/no-pool-nginx.git no-pool-nginx
git clone https://github.com/openresty/nginx-devel-utils.git
git clone https://github.com/openresty/lua-upstream-nginx-module.git lua-upstream-nginx-module
git clone https://github.com/openresty/echo-nginx-module.git echo-nginx-module
git clone https://github.com/openresty/nginx-eval-module.git nginx-eval-module
git clone https://github.com/simpl/ngx_devel_kit.git ndk-nginx-module
git clone https://github.com/FRiCKLE/ngx_coolkit.git coolkit-nginx-module
git clone https://github.com/openresty/headers-more-nginx-module.git headers-more-nginx-module
git clone https://github.com/openresty/drizzle-nginx-module.git drizzle-nginx-module
git clone https://github.com/openresty/set-misc-nginx-module.git set-misc-nginx-module
git clone https://github.com/openresty/memc-nginx-module.git memc-nginx-module
git clone https://github.com/openresty/rds-json-nginx-module.git rds-json-nginx-module
git clone https://github.com/openresty/srcache-nginx-module.git srcache-nginx-module
git clone https://github.com/openresty/redis2-nginx-module.git redis2-nginx-module
# Install drizzle-nginx-module
export DRIZZLE_VERSION=2011.07.21
export LIBDRIZZLE_PREFIX=/opt/drizzle
export LIBDRIZZLE_INC=$LIBDRIZZLE_PREFIX/include/libdrizzle-1.0
export LIBDRIZZLE_LIB=$LIBDRIZZLE_PREFIX/lib
cd $HOME
wget https://openresty.org/download/drizzle7-$DRIZZLE_VERSION.tar.gz
tar -zxf drizzle7-$DRIZZLE_VERSION.tar.gz && rm drizzle7-$DRIZZLE_VERSION.tar.gz
cd drizzle7-$DRIZZLE_VERSION/
./configure --prefix=$LIBDRIZZLE_PREFIX --without-server
make libdrizzle-1.0 -j$JOBS
sudo make install-libdrizzle-1.0
# Install Test::Nginx
cd $HOME
git clone https://github.com/openresty/test-nginx.git
cd test-nginx/
sudo cpanm .
# Install mockeagain
cd $HOME
git clone https://github.com/openresty/mockeagain.git
cd mockeagain
make -j$JOBS
export LD_PRELOAD=$HOME/mockeagain/mockeagain.so
# Install lua-cjson
cd $HOME
git clone https://github.com/openresty/lua-cjson.git
cd lua-cjson
make -j$JOBS
sudo make install
# Install pcre
export PCRE_VER=8.33
export PCRE_PREFIX=/opt/pcre
export PCRE_LIB=$PCRE_PREFIX/lib
export PCRE_INC=$PCRE_PREFIX/include
cd $HOME
wget -O pcre-$PCRE_VER.tar.gz http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VER.tar.gz
tar -zxf pcre-$PCRE_VER.tar.gz && rm pcre-$PCRE_VER.tar.gz
cd pcre-$PCRE_VER/
./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties
make -j$JOBS
sudo PATH=$PATH make install
# Install openssl
export OPENSSL_PREFIX=/opt/ssl
export OPENSSL_LIB=$OPENSSL_PREFIX/lib
export OPENSSL_INC=$OPENSSL_PREFIX/include
export OPENSSL_VER=1.0.2h
cd $HOME
wget -O openssl-$OPENSSL_VER.tar.gz https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
tar -zxf openssl-$OPENSSL_VER.tar.gz && rm openssl-$OPENSSL_VER
cd openssl-$OPENSSL_VER
wget https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-$OPENSSL_VER-sess_set_get_cb_yield.patch
patch -p1 < openssl-$OPENSSL_VER-sess_set_get_cb_yield.patch
./config shared --prefix=$OPENSSL_PREFIX -DPURIFY
make -j$JOBS
sudo make PATH=$PATH install_sw
# Build lua-nginx-module
export NGINX_VERSION=1.9.15
export NGX_BUILD_JOBS=$JOBS
export TEST_NGINX_SLEEP=0.006
cd $HOME
git clone https://github.com/openresty/lua-nginx-module
cd lua-nginx-module
export PATH=$PWD/work/nginx/sbin:$HOME/nginx-devel-utils:$PATH
sh util/build.sh $NGINX_VERSION
# Persist environment
echo "export JOBS=$JOBS" >> /home/vagrant/.profile
echo "export DEBIAN_FRONTEND=$DEBIAN_FRONTEND" >> /home/vagrant/.profile
echo "export PERL_MM_USE_DEFAULT=$PERL_MM_USE_DEFAULT" >> /home/vagrant/.profile
echo "export CC=$CC" >> /home/vagrant/.profile
echo "export LUA_JIT_VERSION=$LUA_JIT_VERSION" >> /home/vagrant/.profile
echo "export LUAJIT_PREFIX=$LUAJIT_PREFIX" >> /home/vagrant/.profile
echo "export LUAJIT_LIB=$LUAJIT_LIB" >> /home/vagrant/.profile
echo "export LUAJIT_INC=$LUAJIT_INC" >> /home/vagrant/.profile
echo "export LUA_INCLUDE_DIR=$LUA_INCLUDE_DIR" >> /home/vagrant/.profile
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> /home/vagrant/.profile
echo "export DRIZZLE_VERSION=$DRIZZLE_VERSION" >> /home/vagrant/.profile
echo "export LIBDRIZZLE_PREFIX=$LIBDRIZZLE_PREFIX" >> /home/vagrant/.profile
echo "export LIBDRIZZLE_INC=$LIBDRIZZLE_INC" >> /home/vagrant/.profile
echo "export LIBDRIZZLE_LIB=$LIBDRIZZLE_LIB" >> /home/vagrant/.profile
echo "export LD_PRELOAD=$LD_PRELOAD" >> /home/vagrant/.profile
echo "export PCRE_VER=$PCRE_VER" >> /home/vagrant/.profile
echo "export PCRE_PREFIX=$PCRE_PREFIX" >> /home/vagrant/.profile
echo "export PCRE_LIB=$PCRE_LIB" >> /home/vagrant/.profile
echo "export PCRE_INC=$PCRE_INC" >> /home/vagrant/.profile
echo "export OPENSSL_PREFIX=$OPENSSL_PREFIX" >> /home/vagrant/.profile
echo "export OPENSSL_LIB=$OPENSSL_LIB" >> /home/vagrant/.profile
echo "export OPENSSL_INC=$OPENSSL_INC" >> /home/vagrant/.profile
echo "export OPENSSL_VER=$OPENSSL_VER" >> /home/vagrant/.profile
echo "export NGINX_VERSION=$NGINX_VERSION" >> /home/vagrant/.profile
echo "export NGX_BUILD_JOBS=$NGX_BUILD_JOBS" >> /home/vagrant/.profile
echo "export TEST_NGINX_SLEEP=$TEST_NGINX_SLEEP" >> /home/vagrant/.profile
echo "export PATH=$PATH" >> /home/vagrant/.profile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = 'bento/ubuntu-14.04'
config.ssh.forward_agent = true
config.vm.provision 'shell', path: 'provision.sh', privileged: false, keep_color: true
config.vm.provider 'vmware_fusion' do |v|
v.vmx['memsize'] = '2048'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment