I am trying to follow this tutorial on running a CGI script, but I am encountering some problems with how it is displayed.
I have the following CGI script located in a folder scripts
in my html folder that Apache serves to me.
#!/usr/bin/perl
# hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print <<"EOF";
<HTML>
<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<H1>Hello, world!</H1>
</BODY>
</HTML>
EOF
When I run this script in the console (with ./hello.cgi
), I get the following correct output:
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<H1>Hello, world!</H1>
</BODY>
</HTML>
I am trying to access this on my ec2 instance with a URL like this: http://<ec2-address>.compute-1.amazonaws.com/scripts/hello.cgi
. However, this is what I see:
It is printing out the HTML correctly, but it is also printing everything else out as well.
What am I doing wrong here? Why am I getting a different output when I run the script on the server versus when I run it on the console in the server?