Home: Perl Programming Help: Beginner:
How to Perl CGI script in apache web sever



rammohan
Novice

Feb 25, 2014, 5:17 AM


Views: 3119
How to Perl CGI script in apache web sever

I'm learning Perl . Currently I'm learning Perl CGI script,in this script i wrote one sample hello world program

Code
    #!/usr/bin/perl -w 
# hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print "Hello, world!\n";

I saved above script in /usr/local/apache2/cgi-bin/hello.pl
For this I installed apache web server in my machine, I checked this web server by using http://localhost it works fine. Then i run my hello.pl program in my browser by using apache server

http://localhost/cgi-bin/hello.pl

but above url showing error.

Code
    Not Found 

The requested URL /cgi-bin/hello.pl was not found on this server.

Apache/2.2.15 (CentOS) Server at localhost Port 80


why it showing this. Is there any thing wong in script or in apache? Did any one face this problem? Please let me know,try to resolve this problem

Code
I also attached httpd.conf file



(This post was edited by rammohan on Feb 25, 2014, 9:12 PM)
Attachments: httpd.conf (13.3 KB)


FishMonger
Veteran / Moderator

Feb 25, 2014, 6:52 AM


Views: 3113
Re: [rammohan] How to Perl CGI script in apache web sever

Why did you start a new thread for this issue when we were working on it in your prior thread?

Please post the output of these commands:

Code
ls -l /usr/local/apache2/cgi-bin/hello.pl


Code
cat /usr/local/apache2/cgi-bin/hello.pl


Code
/usr/bin/od -c /usr/local/apache2/cgi-bin/hello.pl

Use the code tags around the output to retain the formatting.

Run your script from the command line and post the output.

Restart apache then run the script from the browser and post the complete error message from the web server error log.

Post the complete httpd.conf file as an attachment.


rammohan
Novice

Feb 25, 2014, 9:03 PM


Views: 3087
Re: [FishMonger] How to Perl CGI script in apache web sever

your codes showing following output

Code
[Admin@localhost ~]$ ls -l /usr/local/apache2/cgi-bin/hello.pl 
-rwxr-xr-x. 1 root root 120 Feb 25 16:31 /usr/local/apache2/cgi-bin/hello.pl
[Admin@localhost ~]$ cat /usr/local/apache2/cgi-bin/hello.pl
#!/usr/bin/perl -w
#hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print "Hello, world!\n";



[Admin@localhost ~]$ /usr/bin/od -c /usr/local/apache2/cgi-bin/hello.pl
0000000 # ! / u s r / b i n / p e r l
0000020 - w \n # h e l l o . p l - -
0000040 m y f i r s t p e r l s
0000060 c r i p t ! \n p r i n t " C o
0000100 n t e n t - t y p e : t e x t
0000120 / h t m l \ n \ n " ; \n p r i n
0000140 t " H e l l o , w o r l d !
0000160 \ n " ; \n \n \n \n
0000170
[Admin@localhost ~]$



rammohan
Novice

Feb 25, 2014, 9:10 PM


Views: 3082
Re: [FishMonger] How to Perl CGI script in apache web sever

I also attached screen shot after running my url in browser.. I did all the steps what u said.. still same error
Attachments: Screenshot.png (53.7 KB)


rammohan
Novice

Feb 25, 2014, 9:20 PM


Views: 3078
Re: [FishMonger] How to Perl CGI script in apache web sever

this program in running well in terminal

Code
[Admin@localhost cgi-bin]$ perl hello.pl  
Content-type: text/html

Hello, world!


Please see attached screen shot and attached file.


(This post was edited by rammohan on Feb 25, 2014, 9:22 PM)
Attachments: httpd.conf (13.3 KB)
  Screenshot.png (53.7 KB)


FishMonger
Veteran / Moderator

Feb 26, 2014, 6:18 AM


Views: 3051
Re: [rammohan] How to Perl CGI script in apache web sever

What is the exact error message reported in the log file?
/etc/httpd/logs/error_log


rammohan
Novice

Feb 27, 2014, 4:11 AM


Views: 3020
Re: [FishMonger] How to Perl CGI script in apache web sever

Thank you achieved my goal