CGI in C++

Common Gateway Interface (CGI) is a standard way for web servers to interface with executable program installed on a server that generate web pages dynamically.

  • Open directory /etc/apache2/
  • Create a new file “httpd.cfg” with following content
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler cgi-script
Order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl
  • Include “httpd.cfg” in /etc/apache2/apache2.conf by adding following
Include httpd.cfg
  •  Now go to /usr/lib/cgi-bin/ and create a file named “test.cpp” with following contents-
using namepace std;

int main(){
cout<<"cgi is working";
return 0;
  • Now compile the file using following command-
$ g++ test.cpp -o test.out
  • Now open the browser and type-
  • You will see a nice “Hello World!” on screen.

–via Damanpreet


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s