# To use CGI scripts: AddHandler cgi-script .cgi # To use server-parsed HTML files AddType text/html .shtml AddHandler server-parsed .shtml3) Save changes to srm.conf and quit the text editor. If you get an error, make sure you are logged in as root.
4) Restart the Apache server. To do this, enter on the command line:
cd /etc/rc.d/init.d ./httpd restart
1) Navigate to the cgi-bin directory served by Apache:
cd /home/httpd/cgi-bin2) Create a new file called helloworld.cgi. Enter the following lines, then save helloworld.cgi in the cgi-bin directory and quit the text editor.
#!/usr/bin/perl # SSI test file print "Content-type: text/html\n\n"; print "Hello world"; exit;3) Check the file was created okay, enter:
ls -lYou should see:
-rwxrwxr-- 1 root root 108 May 23 19:21 helloworld.cgi4) Make the helloworld.cgi file executable, like so:
chmod +x helloworld.cgi5) Test it works, enter:
perl helloworld.cgiYou should see:
Content-type: text/html Hello worldThis means Perl processed helloworld.cgi successfully and put the results on the screen. If you get a syntax error, most likely you mis-spelt something or forgot a semicolon.
6) Next navigate to the HTML directory, enter:
cd /home/httpd/html7) Make a new file called helloworld.shtml, don't forget the s, and enter the following lines:
<html> <body> Test next line <!--#exec cgi="/cgi-bin/helloworld.cgi"--> </body> </html>8) Save helloworld.shtml in the html directory, then quit the text editor.
If you get an error, navigate to /var/log/httpd and view the file 'error_log' to find out what's the matter. If the error log says "Invalid CGI ref" it means the reference to the CGI script in the HTML file is incorrect. Check against the HTML file shown in point 7 above.
If the hello world text doesn't appear in the browser, maybe you haven't restarted Apache.
If the Perl program code appears in the browser, it means Apache hasn't been configured to process files ending in .cgi as CGI scripts. Solution: make sure the following line is uncommented in your server configuration files:
AddHandler cgi-script .cgi
<html> <body> Test next line Hello world </body> </html>The browser really does have no idea there's script on the original page. That's because the server does all the work and gives the finished HTML to the browser.