How to install Openresty on Ubuntu 18.04

Openresty is a web app server built on popular Nginx web server with lots of advanced features built-in. It is almost a drop-in replacement for Nginx.

Openresty has many built-in Nginx modules that make it a powerful web app server. A most popular feature of Openresty is built-in Lua programming language support. You can directly use Lua scripts inside the Nginx conf files. You can write a high performance web application in Lua without having to install any other package other then Openresty.

For this guide, I will be using a fresh 1GB server from Vultr hosted in Germany.

There are 2 ways to install Openresty. Either you can use the prebuilt binaries or you can download the source and compile it yourself.

For this guide, I will be using the first method as it is easier and also it makes it easier to update Openresty later.

Step 1: Import the GPG key:

We need to import a GPG key as the package we will be downloading is encrypted and this key helps in verifying the package’s authenticity. Run following command to download and add the GPG key from the Openresty official server.

wget -qO - | sudo apt-key add -

Step 2: Add Openresty repository:

Let us first add the apt-add-repository command

sudo apt-get -y install software-properties-common

Now run below command to add the repository. This command will detect the version of ubuntu you are using and add the appropriate repository.

sudo add-apt-repository -y "deb $(lsb_release -sc) main"

Now you will have the official Openresty apt repository added to your system.

Step 3: Install Openresty:

First let’s update the apt index. Use this command to do so

sudo apt-get update

Now run this command to download and install the Openresty from its official repository

sudo apt-get install openresty

If everything goes well you will have Openresty successfully installed of your server.

Check it by visiting the IP address of your server. You will see a page like this:


Bonus tip:

If you are trying to replace previously installed Nginx with Openresty rather the installing it on fresh server then disable and stop the Nginx before following this tutorial.

Disable Nginx with this command

sudo systemctl disable nginx

and stop Nginx with this command

sudo systemctl stop nginx

If you face any problem while installing openresty please let me know in the comments section so we can solve it together.