Friday, February 10, 2012

Dynamic Content with CGI


1. Edit httpd.conf

vi /etc/httpd/conf/httpd.conf
-------------------------------
AddHandler cgi-script .cgi .pl 


        ...
        ...
    ScriptAlias /cgi-bin/ /home/user/www.yourdomain.com/cgi-bin/

-------------------------------


2. Restart httpd

service httpd restart


3. Create a perl script

cd /home/user/www.yourdomain.com/cgi-bin/
vi hello.pl
-------------------------------
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";
print "Hello, World.";
-------------------------------
chmod +x hello.pl


4. Test with web browser

http://www.yourdomain.com/cgi-bin/hello.pl