others-How to install openresty from source on ubuntu system?

1. Purpose

In this post, I would demonstrate how to install openresty on ubuntu system from source.



2. The solution

2.1 What is openresty?

OpenResty is a web platform based on nginx which can run Lua scripts using its LuaJIT engine.[1] The software was created by Yichun Zhang. It was originally sponsored by Taobao before 2011 and was mainly supported by Cloudflare from 2012 to 2016. Since 2017, it has been mainly supported by OpenResty Software Foundation and OpenResty Inc.

OpenResty is designed to build scalable web applications, web services, and dynamic web gateways. The OpenResty architecture is based on several nginx modules which have been extended in order to expand nginx into a web app server to handle large number of requests. The concept of the OpenResty solution aims to run server-side web app completely in the nginx server, leveraging nginx event model to do non-blocking I/O not only with the HTTP clients, but also with remote backends like MySQL, PostgreSQL, Memcached, and Redis.


2.2 Where to download the source code of openresty?

wget https://openresty.org/download/openresty-1.19.9.1.tar.gz


2.3 The installation process on ubuntu system.

unzip the openresty tarball file:

tar zxvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1


prepare for installation:

apt-get update -y
apt-get install -y libpcre3-dev \
  libssl-dev \
  perl \
  make \
  build-essential \
  curl \
  zlib1g-dev


Then configure as follows:

./configure --prefix=/opt/openresty \
	--without-http_fastcgi_module \
	--without-http_scgi_module \
	--with-http_gzip_static_module \
  --with-http_v2_module \
  --with-http_stub_status_module
  


and then compile and install the openresty from source code :

make && make install


Let’s explore the installed directory /opt/openresty/bin:

root[email protected]:/opt/openresty/bin# ll
total 172
drwxr-xr-x 2 root root  4096 Jan  8 20:29 ./
drwxr-xr-x 8 root root  4096 Jan  8 20:29 ../
-rwxr-xr-x 1 root root 19185 Jan  8 20:29 md2pod.pl*
-rwxr-xr-x 1 root root 15994 Jan  8 20:29 nginx-xml2pod*
lrwxrwxrwx 1 root root    31 Jan  8 20:29 openresty -> /opt/openresty/nginx/sbin/nginx*
-rwxr-xr-x 1 root root 63510 Jan  8 20:29 opm*
-rwxr-xr-x 1 root root 36617 Jan  8 20:29 resty*
-rwxr-xr-x 1 root root 14957 Jan  8 20:29 restydoc*
-rwxr-xr-x 1 root root  8873 Jan  8 20:29 restydoc-index*


Let’s start openresty:

[email protected]:/opt/openresty/bin# ./openresty


Then verify that openresty is running:

[email protected]:/opt/openresty/bin# lsof -i:80
COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun   876   root   19u  IPv4  18981      0t0  TCP launch-advisor-20191120:45136->100.100.30.25:http (ESTABLISHED)
openresty 32381   root    8u  IPv4 568547      0t0  TCP *:http (LISTEN)
openresty 32382 nobody    8u  IPv4 568547      0t0  TCP *:http (LISTEN)


At last, we can visit the home page of installed openresty:

[email protected]:/opt/openresty/bin# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Welcome to OpenResty!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to our
<a href="https://openresty.org/">openresty.org</a> site<br/>
Commercial support is available at
<a href="https://openresty.com/">openresty.com</a>.</p>
<p>We have articles on troubleshooting issues like <a href="https://blog.openresty.com/en/lua-cpu-flame-graph/?src=wb">high CPU usage</a> and
<a href="https://blog.openresty.com/en/how-or-alloc-mem/">large memory usage</a> on <a href="https://blog.openresty.com/">our official blog site</a>.
<p><em>Thank you for flying <a href="https://openresty.org/">OpenResty</a>.</em></p>
</body>
</html>


Then stop openresty:

[email protected]:/opt/openresty/bin# ./openresty -s stop


Verify openresty is stopped:

[email protected]:/opt/openresty/bin# curl http://localhost
curl: (7) Failed to connect to localhost port 80: Connection refused
[email protected]:/opt/openresty/bin#



3. Summary

In this post, I demonstrated how to install openresty from souce on ubuntu system. That’s it, thanks for your reading.

-->