Vely logo Empower C
install     tutorials     examples     documentation     license     about

11.0.11 released on Jul 25, 2022

CGI



DESCRIPTION:


You can run Vely application as a CGI (Common Gateway Interface) program, if your web server supports CGI. This is not recommended in general, as CGI programs do not exhibit great performance. However in some cases you may need to use CGI, such as when performance is not of critical importance.

To run your application with CGI, use Vely command_line program. Since Vely applications require running in the security context of the user who owns the application, you must use "suexec" (or similar feature) of your web server.

The following script sets up application "func_test" to run as CGI (after it's been compiled with vv) on Apache web server running on Ubuntu 18 and up. For other web servers/distros, consult their documentation on how to setup CGI for a program.
#prep repos
    sudo apt update

#enable CGI on apache
    sudo a2enmod cgid
    sudo service apache2 restart

#Install suexec-custom for Apache
    sudo apt-get install apache2-suexec-custom
    sudo a2enmod suexec
    sudo service apache2 restart

#setup a "vv" directory under cgi-bin where your application can run
    sudo mkdir -p /usr/lib/cgi-bin/vv
    sudo chown $(whoami):$(whoami)  /usr/lib/cgi-bin/vv
    sudo sed -i '1c\/usr/lib/cgi-bin/vv' /etc/apache2/suexec/www-data

#copy your program to "vv" directory
    sudo mv /var/lib/vv/bld/func_test/func_test /usr/lib/cgi-bin/vv
    sudo chown $(whoami):$(whoami)  /usr/lib/cgi-bin/vv/func_test
    sudo chmod 700  /usr/lib/cgi-bin/vv/func_test

#add user/group of Vely application user to suexec
    sudo sed -i "/SuexecUserGroup/d" /etc/apache2/sites-enabled/000-default.conf
    sudo sed -i "s/<\/VirtualHost>/SuexecUserGroup $(whoami) $(whoami)\n<\/VirtualHost>/g" /etc/apache2/sites-enabled/000-default.conf
    sudo service apache2 restart

#run application, and test it's working
    RES=$(curl -s "http://127.0.0.2/cgi-bin/vv/func_test?req=run" |grep "VELDONE"|wc -l)
    if [ "$RES" != "1" ]; then
        echo "VELERROR $LINENO cgi"
    fi


SEE ALSO:


Running application ( plain_C_FCGI   containerize_application   command_line   application_setup   CGI   FastCGI   FastCGI_client  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. This web page is licensed under CC-BY-SA-4.0.