Skip to main content

How to add CGI and Perl in apache

Configuring Apache to run CGI programs isn't that hard. First, you need to assign an alias for your script directory.

So you create a special location, called an alias, to the actual CGI directory. Edit your httpd.conf file and add the line below:

ScriptAlias /cgi-bin/  /usr/local/apache/share/cgi-bin/

However, this does not configure Apache to run the programs it finds in the cgi-bin directory. To actually execute programs, you need to edit the access.conf file by adding a section like this:

<Directory /usr/local/apache/share/cgi-bin>
Options ExecCGI
AddHandler cgi-script   .cgi   .pl
</Directory>

 

Here is how CGI works

CGI test

You need a web page that uses forms to call the cgi script. Create a plain text file

called testcgi.html

Here it is:
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>

<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>testcgi</title>

</head><body>
<form action="cgi-bin/mycgi.cgi">
<input name="Firstname" type="text">
<input value="OK" type="submit">
</form>
<br>

</body></html>


Create a plain text file called mycgi.cgi

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "That worked\n";
exit(0);


The script will fail if it has the wrong permissions, and it needs to be in a directory called

cgi-bin

which also has the correct permissions.

Using an ftp client such as filezilla,

  • upload testcgi.html to the top-level of your account.

  • create a directory called cgi-bin

  • upload mycgi.cgi to cgi-bin

  • change the permissions of cgi-bin to 75


Browse to your home page
http://www.WhereEver-It-Is/~YourUserName/testcgi.html

You will see a form. Type xxxx into it and click the OK button.

The URL line will change to
http://www.WhereEver-It-Is/~YourUserName/cgi-bin/ 
mycgi.cgi?Firstname=xxxx

The page will display
That worked

Comments

Popular posts from this blog

Freenom ICANN registrar accreditation suspended for cybersquatting

OpenTLD, its registrar business, has been told it cannot accept new registrations or inbound transfers from July 8 to October 6 or until it provides ICANN with a full list of the names it squatted. I believe it’s the first time ICANN has suspended a registrar for this reason. ICANN has found that OpenTLD has engaged in a pattern and practice of trafficking in or use of domain names identical or confusingly similar to a trademark or service mark of a third party in which the Registered Name Holder has no rights or legitimate interest   To avoid termination, it has to provide ICANN with a list of all of its trademark infringing names, agree to transfer them to the mark owners or delete them, and bunch of other stuff. Source Letter

Will 5G cause a Digital divide in society ?

How 5G make huge difference in future and its negative impact on you.