Installation

Quick Install (Linux)

The fastest way to install js-cgi:

curl -sSL https://js-cgi.com/install.sh -o install.sh
sudo bash install.sh

The interactive installer detects your architecture, installs dependencies, downloads the latest release, and optionally configures your web server.

Build from Source

If you prefer to compile js-cgi yourself, or need to customise the build:

Dependencies

sudo apt-get install -y gcc make git libsqlite3-dev libssl-dev libcurl4-openssl-dev

Clone and Build

git clone https://github.com/js-cgi/js-cgi.git
cd js-cgi
./build.sh

Build Extensions

gcc -shared -fPIC -O2 -I. -o extensions/sqlite/sqlite.so extensions/sqlite/sqlite.c -lsqlite3
gcc -shared -fPIC -O2 -I. -o extensions/crypto/crypto.so extensions/crypto/crypto.c -lssl -lcrypto
gcc -shared -fPIC -O2 -I. -o extensions/http/http.so extensions/http/http.c -lcurl
gcc -shared -fPIC -O2 -I. -o extensions/session/session.so extensions/session/session.c
gcc -shared -fPIC -O2 -I. -o extensions/file/file.so extensions/file/file.c

Install

sudo cp js-cgi /usr/lib/cgi-bin/js-cgi
sudo mkdir -p /usr/lib/js-cgi/modules
sudo cp extensions/*/*.so /usr/lib/js-cgi/modules/
sudo mkdir -p /etc/js-cgi
sudo cp js-cgi.ini /etc/js-cgi/js-cgi.ini

Apache Configuration

Enable the required Apache modules:

sudo a2enmod cgid actions

Create a virtual host configuration at /etc/apache2/sites-available/js-cgi.conf:

<VirtualHost *:80>
    DocumentRoot /var/www/js
    DirectoryIndex index.js

    Action js-cgi /cgi-bin/js-cgi
    AddHandler js-cgi .js

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    <Directory /var/www/js>
        Options +ExecCGI
        Require all granted
    </Directory>

    <Directory /usr/lib/cgi-bin>
        Require all granted
    </Directory>
</VirtualHost>

Enable the site and restart Apache:

sudo mkdir -p /var/www/js
sudo a2dissite 000-default
sudo a2ensite js-cgi
sudo systemctl restart apache2

Verify

Create /var/www/js/index.js:

const name = request.query.name || "World";
print(`<h1>Hello, ${name}!</h1>`);

Visit http://your-server/index.js?name=Developer and you should see:

Hello, Developer!

Was this page helpful?