By default when you install
apache2, and navigate to /var/www directory you won't find the
cgi-bin folder. To enable CGI in
apache2 follow this steps -
$ sudo apt install apache2 -y
We can find the available
/etc/apache2/mods-available. Here you will see the
cgi.load module which you need to load.
$ sudo ln -s /etc/apache2/mods-available/cgi.load
Now as Apache configuration has changed, reload the apache service by -
$ sudo service apache2 reload
Apache2 recognizes cgi-scripts in the directory
/usr/lib/cgi-bin, so we need to place the script in this folder.
Lets create a cgi script in python that returns the output of
free -m command.
#!/usr/bin/python3 from subprocess import getstatusoutput as gso import cgi print("content-type:text/plain") print() print(gso("free -m"))
Make this script executable by -
$ sudo chmod +x c.py
curl to get response
Connect with me -