Skip to content

Building OpenResty

aborkar-ibm edited this page Sep 21, 2017 · 52 revisions

Building OpenResty

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

  • RHEL (6.9, 7.1, 7.2, 7.3)
  • SLES (11 SP4, 12, 12 SP1, 12 SP2)
  • Ubuntu (16.04, 16.10, 17.04)

Prerequisites:

  • LuaJIT -- Instructions for building LuaJIT can be found here

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.

Step 1: Install the dependencies

  • RHEL 6.9

    sudo yum install -y git tar wget make gcc gcc-c++ unix2dos hg postgresql-devel patch pcre-devel readline-devel openssl openssl-devel 
    
    • Build GCC 4.8.2:

       cd /<source_root>/
       sudo yum install -y binutils-devel bzip2
       wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
       tar xvf gcc-4.8.2.tar.bz2
       cd gcc-4.8.2
       ./contrib/download_prerequisites
       mkdir /<source_root>/gccbuild
       cd /<source_root>/gccbuild
       ../gcc-4.8.2/configure  --prefix="/opt/gcc"  --enable-shared --with-system-zlib --enable-threads=posix  --enable-__cxa_atexit --enable-checking --enable-gnu-indirect-function  --enable-languages="c,c++" --disable-bootstrap --disable-multilib
       make all
       sudo make install
       export PATH=/opt/gcc/bin:$PATH
       export LD_LIBRARY_PATH=/opt/gcc/lib64:/opt/gcc/lib:$LD_LIBRARY_PATH
       sudo mv /usr/bin/gcc /usr/bin/gcc.bkup
       sudo ln -s /opt/gcc/bin/gcc /usr/bin/gcc
    • Install Perl 5.24.1

       cd /<source_root>
       wget http://www.cpan.org/src/5.0/perl-5.24.1.tar.gz
       tar xvf perl-5.24.1.tar.gz
       cd perl-5.24.1
       ./Configure -des -Dprefix=/usr/local/perl -Dnoextensions=ODBM_File
       make
       sudo make install
       export PATH=/usr/local/perl/bin/:$PATH
       perl -v
  • RHEL (7.1, 7.2, 7.3)

    sudo yum install -y git tar wget make gcc gcc-c++ unix2dos hg cpan perl postgresql-devel patch pcre-devel readline-devel openssl openssl-devel 
    
  • SLES 11 SP4

    sudo zypper install -y git tar wget make gcc gcc-c++ mercurial patch pcre-devel readline-devel openssl libopenssl-devel aaa_base awk flex bison
    
    • Install unix2dos 4.1

       cd /<source_root>
       wget https://waterlan.home.xs4all.nl/unix2dos/unix2dos-4.1.tar.gz
       tar xvf unix2dos-4.1.tar.gz
       cd unix2dos-4.1
       make
       sudo make install
    • Install Perl 5.24.1

       cd /<source_root>
       wget http://www.cpan.org/src/5.0/perl-5.24.1.tar.gz
       tar xvf perl-5.24.1.tar.gz
       cd perl-5.24.1
       ./Configure -des -Dprefix=/usr/local/perl -Dnoextensions=ODBM_File
       make
       sudo make install
       export PATH=/usr/local/perl/bin/:$PATH
       perl -v
    • Install PostgreSQL 9.6.2

       cd /<source_root>
       git clone https://github.com/postgres/postgres.git
       cd postgres
       git checkout REL9_6_2
       ./configure
       make && sudo make install
       export PATH=$PATH:/usr/local/pgsql/bin
       export LD_LIBRARY_PATH=/usr/local/pgsql/lib
  • SLES (12, 12 SP1, 12 SP2)

    sudo zypper install -y git tar wget make gcc gcc-c++ unix2dos hg perl postgresql-devel patch pcre-devel readline-devel openssl openssl-devel aaa_base
    
  • Ubuntu (16.04, 16.10, 17.04)

    sudo apt-get update
    sudo apt-get install -y git tar wget make gcc dos2unix hgview libreadline-dev patch libpcre3-dev libpcre3 libcurl4-openssl-dev libncursesada*-dev postgresql libpq-dev openssl libssl-dev perl
    sudo ln -s make /usr/bin/gmake
    

Note: Set /sbin to your PATH environment variable if not already set.

Step 2: Download the source code

cd /<source_root>
git clone https://github.com/openresty/openresty.git
cd openresty
git checkout v1.11.2.4

Step 3: Comment out the below lines in file /<source_root>/openresty/util/configure

# {
         # check -msse4.2
#        my ($out, $cfile) = tempfile("resty-config-XXXXXX",
#                                      SUFFIX => '.c', TMPDIR => 1,
#                                      UNLINK => 1);

#        print $out "int main(void) { return 0; }";
#        close $out;

#        my $ofile = tmpnam();
#        my $comp = ($cc || 'cc');

#        if (system("$comp -o $ofile -msse4.2 -c $cfile") == 0 && -s $ofile) {
#            print "INFO: found -msse4.2 in $comp.\n";
#            $luajit_xcflags .= " -msse4.2";
#            unlink $ofile;

#        } else {
#            print "WARNING: -msse4.2 not supported in $comp.\n";
#        }
#    }

Note: -msse4.2 compilation option is not supported on s390x.

Step 4: Build and install OpenResty

cd /<source_root>/openresty    
make

Note: If make fails with the error POD document had syntax errors at /usr/bin/pod2text. , ignore the ngx_http_api_module by executing rm -f /<source_root>/openresty/work/nginx.org/xml/en/docs/http/ngx_http_api_module.xml , rm -f /<source_root>/openresty/work/nginx.org/ngx_http_api_module.pod and run make again. This issue has been fixed in the master branch.

rm -rf /<source_root>/openresty/openresty-1.11.2.4/bundle/LuaJIT-2.1-20170405/
cp -r /<source_root>/LuaJIT /<source_root>/openresty/openresty-1.11.2.4/bundle/LuaJIT-2.1-20170405/
cd /<source_root>/openresty/openresty-1.11.2.4
./configure --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module  -j2 
make -j2 
sudo make install

Step 5: Configure Nginx module

cd /<source_root>/openresty/openresty-1.11.2.4/build/nginx-1.11.2
./configure && make && sudo make install

Step 6: Install cpan modules

sudo cpan Cwd IPC::Run3 Test::Base Test::LongString

Notes:

1. For options prompted please select the default option.

2. In RHEL 6.9 or SLES 11 SP4, if you get the error sudo: cpan: command not found , use the absolute path for cpan.

3. If you get the warning perl: warning: Setting locale failed. , set LANG environment variable.

  export LANG=C

Step 7: Edit file /<source_root>/openresty/t/sanity.t

  • Ubuntu (16.04, 16.10, 17.04)
@@ -1638,8 +1638,8 @@ clean:
platform: linux (linux)
cp -rp bundle/ build
cd build
-export LIBPQ_LIB='/usr/lib64'
-export LIBPQ_INC='/usr/include'
+export LIBPQ_LIB='/usr/lib/s390x-linux-gnu'
+export LIBPQ_INC='/usr/include/postgresql'
cd LuaJIT-2.1-20170405
INFO: found -msse4.2 in cc.
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT -msse4.2' CC=cc PREFIX=/usr/local/openresty/luajit
@@ -1668,7 +1668,7 @@ sh ./configure --prefix=/usr/local/openresty/nginx \
 --add-module=../redis-nginx-module-0.3.7 \
 --add-module=../rds-json-nginx-module-0.14 \
 --add-module=../rds-csv-nginx-module-0.07 \
-  --with-ld-opt='-Wl,-rpath,/usr/lib64:/usr/local/openresty/luajit/lib' \
+  --with-ld-opt='-Wl,-rpath,/usr/lib/s390x-linux-gnu:/usr/local/openresty/luajit/lib' \
 --with-http_ssl_module
cd ../..
Type the following commands to build and install:
  • SLES 11 SP4
@@ -1638,8 +1638,8 @@ clean:
platform: linux (linux)
cp -rp bundle/ build
cd build
-export LIBPQ_LIB='/usr/lib64'
-export LIBPQ_INC='/usr/include'
+export LIBPQ_LIB='/usr/local/pgsql/lib'
+export LIBPQ_INC='/usr/local/pgsql/include'
cd LuaJIT-2.1-20170405
INFO: found -msse4.2 in cc.
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT -msse4.2' CC=cc PREFIX=/usr/local/openresty/luajit
@@ -1668,7 +1668,7 @@ sh ./configure --prefix=/usr/local/openresty/nginx \
 --add-module=../redis-nginx-module-0.3.7 \
 --add-module=../rds-json-nginx-module-0.14 \
 --add-module=../rds-csv-nginx-module-0.07 \
-  --with-ld-opt='-Wl,-rpath,/usr/lib64:/usr/local/openresty/luajit/lib' \
+  --with-ld-opt='-Wl,-rpath,/usr/local/pgsql/lib:/usr/local/openresty/luajit/lib' \
 --with-http_ssl_module
cd ../..
Type the following commands to build and install:
  • SLES 12
@@ -1638,8 +1638,8 @@ clean:
platform: linux (linux)
cp -rp bundle/ build
cd build
-export LIBPQ_LIB='/usr/lib64'
-export LIBPQ_INC='/usr/include'
+export LIBPQ_LIB='/usr/lib/postgresql93/lib64'
+export LIBPQ_INC='/usr/include/pgsql'
cd LuaJIT-2.1-20170405
INFO: found -msse4.2 in cc.
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT -msse4.2' CC=cc PREFIX=/usr/local/openresty/luajit
@@ -1668,7 +1668,7 @@ sh ./configure --prefix=/usr/local/openresty/nginx \
 --add-module=../redis-nginx-module-0.3.7 \
 --add-module=../rds-json-nginx-module-0.14 \
 --add-module=../rds-csv-nginx-module-0.07 \
-  --with-ld-opt='-Wl,-rpath,/usr/lib64:/usr/local/openresty/luajit/lib' \
+  --with-ld-opt='-Wl,-rpath,/usr/lib/postgresql93/lib64:/usr/local/openresty/luajit/lib' \
 --with-http_ssl_module
cd ../..
Type the following commands to build and install:
  • SLES (12 SP1, 12 SP2)
@@ -1638,8 +1638,8 @@ clean:
platform: linux (linux)
cp -rp bundle/ build
cd build
-export LIBPQ_LIB='/usr/lib64'
-export LIBPQ_INC='/usr/include'
+export LIBPQ_LIB='/usr/lib/postgresql94/lib64'
+export LIBPQ_INC='/usr/include/pgsql'
cd LuaJIT-2.1-20170405
INFO: found -msse4.2 in cc.
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT -msse4.2' CC=cc PREFIX=/usr/local/openresty/luajit
@@ -1668,7 +1668,7 @@ sh ./configure --prefix=/usr/local/openresty/nginx \
 --add-module=../redis-nginx-module-0.3.7 \
 --add-module=../rds-json-nginx-module-0.14 \
 --add-module=../rds-csv-nginx-module-0.07 \
-  --with-ld-opt='-Wl,-rpath,/usr/lib64:/usr/local/openresty/luajit/lib' \
+  --with-ld-opt='-Wl,-rpath,/usr/lib/postgresql94/lib64:/usr/local/openresty/luajit/lib' \
 --with-http_ssl_module
cd ../..
Type the following commands to build and install:
  • All Distributions
sed -i "/INFO: found -msse4.2 in cc./d" /<source_root>/openresty/t/sanity.t
sed -i "/WARNING: -msse4.2/d" /<source_root>/openresty/t/sanity.t
sed -i "s/ XCFLAGS='-msse4.2'//g" /<source_root>/openresty/t/sanity.t
sed -i "/configure line 641/d" /<source_root>/openresty/t/sanity.t
sed -i "s/ -msse4.2//g" /<source_root>/openresty/t/sanity.t

Step 8: Run test cases (Optional)

export PERL5LIB=/<source_root>/openresty         # For Ubuntu 17.04 only
cd /<source_root>/openresty
make test

Step 9: Verify Openresty version

export PATH=/usr/local/openresty/bin:$PATH
resty -V  

References

https://openresty.org/

Clone this wiki locally