1

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:

Screenshot of output on the server

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?

Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
  • Running CGI in EC2 is the same as on any other Linux distro. Most likely your apache config is not set to execute the script. – Cfreak Jun 27 '17 at 00:04
  • 1
    You do not have a programming question. You have a question about [how to configure Apache to run CGI scripts](https://httpd.apache.org/docs/2.4/howto/cgi.html#configuring). – Sinan Ünür Jun 27 '17 at 00:29

0 Answers0