Skip to content

Building OpenResty

aborkar-ibm edited this page Oct 13, 2021 · 52 revisions

Building OpenResty

The instructions provided below specify the steps to build OpenResty 1.19.3.2 on Linux on IBM Z for the following distributions:

  • RHEL (7.8, 7.9, 8.2, 8.3, 8.4)
  • SLES (12 SP5, 15 SP2, 15 SP3)
  • Ubuntu (18.04, 20.04, 21.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Build and Install OpenResty

Step 1: Build using script

If you want to build OpenResty using manual steps, go to Step 2.

Use the following commands to build OpenResty using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/OpenResty/1.19.3.2/build_openresty.sh
# Build OpenResty
bash build_openresty.sh   [Provide -t option for executing build with tests]

If the build completes successfully, go to STEP 8. In case of error, check logs for more details or go to STEP 2 to follow manual build steps.

Step 2: Install the dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (7.8, 7.9, 8.2, 8.3, 8.4)

    sudo yum install -y curl tar wget make gcc dos2unix cpan perl postgresql-devel patch pcre-devel openssl-devel
  • SLES (12 SP5, 15 SP2, 15 SP3)

    sudo zypper install -y curl tar wget make gcc dos2unix perl postgresql10-devel patch pcre-devel openssl libopenssl-devel gzip
  • Ubuntu (18.04, 20.04, 21.04)

    sudo apt-get update
    sudo apt-get install -y curl tar wget make gcc build-essential dos2unix patch libpcre3-dev libpq-dev openssl libssl-dev perl zlib1g-dev
    sudo ln -s make /usr/bin/gmake 

Note: Set /sbin to your PATH environment variable if not already set. Example: export PATH=$PATH:/sbin

Step 3: Download the source code

cd $SOURCE_ROOT
wget https://openresty.org/download/openresty-1.19.3.2.tar.gz
tar -xvf openresty-1.19.3.2.tar.gz

Step 4: Rollback some modules to previous version due to a lua core issue

cd $SOURCE_ROOT
wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
tar -xvf openresty-1.17.8.2.tar.gz
rm -rf openresty-1.19.3.2/bundle/LuaJIT-2.1-*
rm -rf openresty-1.19.3.2/bundle/lua-resty-core-*
rm -rf openresty-1.19.3.2/bundle/ngx_lua-*
rm -rf openresty-1.19.3.2/bundle/ngx_stream_lua-*
cp -r openresty-1.17.8.2/bundle/LuaJIT-2.1-* openresty-1.19.3.2/bundle/
cp -r openresty-1.17.8.2/bundle/lua-resty-core-* openresty-1.19.3.2/bundle/
cp -r openresty-1.17.8.2/bundle/ngx_lua-* openresty-1.19.3.2/bundle/
cp -r openresty-1.17.8.2/bundle/ngx_stream_lua-* openresty-1.19.3.2/bundle/
rm -rf openresty-1.17.8.2

Step 5: Patch the configure file for older GCC (RHEL 7.x and SLES 12 SP5 only)

cd $SOURCE_ROOT/openresty-1.19.3.2
PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/OpenResty/1.19.3.2/patch"
curl -o "configure.diff" $PATCH_URL/configure.diff
patch -l $SOURCE_ROOT/openresty-1.19.3.2/configure configure.diff

Step 6: Build and Install OpenResty

cd $SOURCE_ROOT/openresty-1.19.3.2
./configure --with-pcre-jit \
            --with-ipv6 \
            --without-http_redis2_module \
            --with-http_iconv_module \
            --with-http_postgres_module
make -j2
sudo make install

Step 7: Testing (Optional)

7.1) Install cpan modules

sudo PERL_MM_USE_DEFAULT=1 cpan Cwd IPC::Run3 Test::Base

Note: For options prompted please select the default option.

7.2) Download files and modify to run sanity tests

mkdir $SOURCE_ROOT/openresty-1.19.3.2/t
cd $SOURCE_ROOT/openresty-1.19.3.2/t
wget https://raw.githubusercontent.com/openresty/openresty/v1.19.3.2/t/Config.pm
wget https://raw.githubusercontent.com/openresty/openresty/v1.19.3.2/t/000-sanity.t
  • Apply patch to file $SOURCE_ROOT/openresty-1.17.8.1/t/Config.pm

    PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/OpenResty/1.19.3.2/patch"
    curl -o "Config.pm.diff"  $PATCH_URL/Config.pm.diff
    patch -l $SOURCE_ROOT/openresty-1.19.3.2/t/Config.pm Config.pm.diff
  • Update the module version based on our change

    sed -i 's/lua-resty-core-0.1.21/lua-resty-core-0.1.19/g' $SOURCE_ROOT/openresty-1.19.3.2/t/000-sanity.t
    sed -i 's/LuaJIT-2.1-20201027/LuaJIT-2.1-20200102/g' $SOURCE_ROOT/openresty-1.19.3.2/t/000-sanity.t
    sed -i 's/ngx_stream_lua-0.0.9/ngx_stream_lua-0.0.8/g' $SOURCE_ROOT/openresty-1.19.3.2/t/000-sanity.t
    sed -i 's/ngx_lua-0.10.19/ngx_lua-0.10.17/g' $SOURCE_ROOT/openresty-1.19.3.2/t/000-sanity.t
  • Revert the patch for configure file (RHEL 7.x and SLES 12 SP5 only)

    cd $SOURCE_ROOT/openresty-1.19.3.2
    curl -o "configure.diff" $PATCH_URL/configure.diff
    patch -l -R $SOURCE_ROOT/openresty-1.19.3.2/configure configure.diff

7.3) Run test cases

cd $SOURCE_ROOT/openresty-1.19.3.2
prove -r t

Step 8: Verify installed Openresty version

export PATH=/usr/local/openresty/bin:$PATH
resty -V
resty -e 'print("hello, world")'

References

https://openresty.org/

Clone this wiki locally