Atlantic.Net Blog

How to Install OpenResty on Rocky Linux 8

OpenResty is an Nginx-based web platform that can run Lua scripts using its LuaJIT engine. It has many built-in Nginx modules that can make it a powerful web app server. OpenResty allows you to use Lua scripts inside the Nginx conf files and write a high-performance web application in Lua without installing any package.

In this post, we will show you how to install OpenResty on Rocky Linux 8.

Step 1 – Install OpenResty on Rocky Linux 8

By default, the OpenResty package is not included in the Rocky Linux 8 default repo, so you will need to add the OpenResty repo to your system. You can add it with the following command:

wget https://openresty.org/package/centos/openresty.repo -O /etc/yum.repos.d/openresty.repo

Once the repo is added, run the following command to install OpenResty on Rocky Linux 8.

dnf install openresty -y

After the installation, verify the OpenResty version using the following command:

openresty -v

You will get the following output:

nginx version: openresty/1.19.9.1

You can also install the OpenResty CLI utility using the following command:

dnf install openresty-resty -y

Next, start and enable the OpenResty service using the following command:

systemctl start openresty
systemctl enable openresty

You can also check the status of OpenResty with the following command:

systemctl status openresty

You will get the following output:

● openresty.service - The OpenResty Application Platform
   Loaded: loaded (/usr/lib/systemd/system/openresty.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-29 06:07:47 UTC; 5s ago
  Process: 8788 ExecStart=/usr/local/openresty/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 8787 ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS)
 Main PID: 8790 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 2.4M
   CGroup: /system.slice/openresty.service
           ├─8790 nginx: master process /usr/local/openresty/nginx/sbin/nginx
           └─8791 nginx: worker process

Jan 29 06:07:47 rockylinux systemd[1]: Starting The OpenResty Application Platform...
Jan 29 06:07:47 rockylinux nginx[8787]: nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
Jan 29 06:07:47 rockylinux nginx[8787]: nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
Jan 29 06:07:47 rockylinux systemd[1]: openresty.service: Failed to parse PID from file /usr/local/openresty/nginx/logs/nginx.pid: Invalid ar>
Jan 29 06:07:47 rockylinux systemd[1]: Started The OpenResty Application Platform.

Also Read

How to Install and Configure Nginx Webserver on Oracle Linux 8

Step 2 – Create a Project with OpenResty

In this section, we will create a sample hello world project using OpenResty.

First, create a directory with the following command:

mkdir resty

Next, change the directory to resty and create the other required directories using the following command:

cd resty
mkdir logs conf

Next, create an Nginx configuration file:

nano conf/nginx.conf

Add the following code:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, world</p>")
            }
        }
    }
}

Save and close the file, then export the Nginx path with the following command:

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH

Next, start the Nginx server with the following command:

nginx -p `pwd`/ -c conf/nginx.conf

This will start an Nginx server on port 8080. You can check it with the ss command:

ss -antpl | grep 8080

You will get the following output:

LISTEN 0      128          0.0.0.0:8080      0.0.0.0:*    users:(("nginx",pid=8806,fd=8),("nginx",pid=8805,fd=8))

Step 3 – Verify OpenResty Project

You can now verify your OpenResty hello world project using the URL http://your-server-ip:8080. You should see the following page:
Open Restry Dashboard
You can also use the curl command to test your project:

curl http://localhost:8080/

You will get the following output:

hello, world

Conclusion

In the above guide, we explained how to install OpenResty on Rocky Linux 8. We also created a sample hello world project and host it using OpenResty. Start working on the OpenResty platform today on dedicated hosts from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year