Run C++ program through CGI

You can run your c++ code through CGI. But you must configure Apache2 with CGI and you must have install cgicc compiler to compile c++ code. Follow below steps to run c++ code through CGI.

1.To configure Apache2 with CGI follow previous post.

2.Create your c++ program file  using vi editer  under /usr/lib/cgi-bin.

$ sudo vi firstCGI.cc

for example: firstCGI.cc

c++ through CGI

3. After completion ,Compile your c++ code using cgicc compiler, If cgicc is not installed then install it using following steps:

  • Download cgicc from : http://ftp.gnu.org/gnu/cgicc/
  • Extract your cgicc file.
  • Now goto directory where your extracted cgicc file is locate. for example: /home/manpreet/Downloads/cgicc-3.2.16
  • Run $ ./configure
  • Run $ make
  • Run $ sudo make install
  • Done (cgicc is installed now)

4. compile c++ code under /usr/lib/cgi-bin directory:

$ sudo g++ -o /usr/lib/cgi-bin/firstCGI firstCGI.cc

5.Change permissions of firstCGI.cc file

$ chmod 755 firstCGI.cc

6. Run your c++ file on browser, type following on address bar

http://localhost/cgi-bin/firstCGI
output:

cgic++

7. Done

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s