10 Replies - 3120 Views - Last Post: 11 November 2012 - 04:44 PM

#1 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Viewing CGI files with Apache

Posted 10 November 2012 - 04:56 PM

Ok, so I've just installed Apache. I've been reading through the directions but am still not totally sure as to how I'm supposed to view these files. I've placed the CGI files in the cgi-bin. The tutorial refers to http://www.example.com/cgi-bin/...pl as the means to view the file. Do I need to get a domain? Or is there something that I'm totally missing?

Thanks in advance...

Is This A Good Question/Topic? 0
  • +

Replies To: Viewing CGI files with Apache

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Viewing CGI files with Apache

Posted 10 November 2012 - 05:23 PM

No, you don't need to get a domain. You can access Apache's files through either a host name (like a domain name or a computer name on a local network) or even an IP address.

As for accessing CGI files, that depends on the configuration. Show us the config file.

A more important question might be: Why on earth are you using CGI? It's a sort of outdated technology that died when languages like PHP and Python become popular as server-side languages. Server side scripts are typically executed either via a Apache module (like mod_php) or through FastCGI.
Was This Post Helpful? 1
  • +
  • -

#3 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Re: Viewing CGI files with Apache

Posted 10 November 2012 - 06:31 PM

View PostAtli, on 10 November 2012 - 05:23 PM, said:

No, you don't need to get a domain. You can access Apache's files through either a host name (like a domain name or a computer name on a local network) or even an IP address.

As for accessing CGI files, that depends on the configuration. Show us the config file.

A more important question might be: Why on earth are you using CGI? It's a sort of outdated technology that died when languages like PHP and Python become popular as server-side languages. Server side scripts are typically executed either via a Apache module (like mod_php) or through FastCGI.



I'm just experimenting.

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";



What would I type into the browser to view this? ...\cgi-bin

This post has been edited by Planet Telex: 10 November 2012 - 06:34 PM

Was This Post Helpful? 0
  • +
  • -

#4 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 11:48 AM

Ok so I've just installed Apache and I've copied and pasted a simple Perl script into the CGI - bin. So when I type the path into the browser...

C:\Program Files (x86)\Apache Group\Apache2\cgi-bin\first.pl

The output is just the text file. Yesterday, when I tried it my comp tried to download and execute the file. So my question is, how can I get the browser to display it in HTML format?

Here is the code:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";



Thanks a lot in advance!

This post has been edited by Planet Telex: 11 November 2012 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 12:04 PM

I've merged your two threads on this issue. Please don't double post your questions!


When you type the local file path of the script into the browser, you are not going through the HTTP server. You are literally asking the browser to show you the Perl script as text, rather than asking it to request the website via the HTTP server.

To request a website through a local HTTP server, you use the URL http://localhost/. To request your Perl script, I would guess the URL would either be http://localhost/cgi-bin/first.pl or http://localhost/first.pl. The exact URL would depend on the server config, though.
Was This Post Helpful? 1
  • +
  • -

#6 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 12:13 PM

View PostAtli, on 11 November 2012 - 12:04 PM, said:

I've merged your two threads on this issue. Please don't double post your questions!


When you type the local file path of the script into the browser, you are not going through the HTTP server. You are literally asking the browser to show you the Perl script as text, rather than asking it to request the website via the HTTP server.

To request a website through a local HTTP server, you use the URL http://localhost/. To request your Perl script, I would guess the URL would either be http://localhost/cgi-bin/first.pl or http://localhost/first.pl. The exact URL would depend on the server config, though.


Thanks for the reply. Hmmm the first link I received an internal server error...

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@oc.cox.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


The second one produced a "Not Found"

Not Found

The requested URL /first.pl was not found on this server.

As you can see I'm a newb.
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 12:20 PM

OK so it looks like the first URL is correct, but that the server is somehow configured incorrectly.

View PostPlanet Telex, on 11 November 2012 - 07:13 PM, said:

More information about this error may be available in the server error log.

This is where you need to look to find out what is actually going wrong. Judging by the path you posted earlier, I'm guessing you'll find the error log in a file at:
- C:\Program Files (x86)\Apache Group\Apache2\logs\error.log
Was This Post Helpful? 1
  • +
  • -

#8 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 12:46 PM

View PostAtli, on 11 November 2012 - 12:20 PM, said:

OK so it looks like the first URL is correct, but that the server is somehow configured incorrectly.

View PostPlanet Telex, on 11 November 2012 - 07:13 PM, said:

More information about this error may be available in the server error log.

This is where you need to look to find out what is actually going wrong. Judging by the path you posted earlier, I'm guessing you'll find the error log in a file at:
- C:\Program Files (x86)\Apache Group\Apache2\logs\error.log


Here is the error log:

Installing the Apache2 service
The Apache2 service is successfully installed.
Starting the Apache2 service
The Apache2 service is running.
ce] Apache/2.0.64 (Win32) configured -- resuming normal operations
[Fri Nov 09 18:49:39 2012] [notice] Server built: Oct 18 2010 01:36:23
[Fri Nov 09 18:49:39 2012] [notice] Parent: Created child process 7120
[Fri Nov 09 18:49:39 2012] [notice] Child 7120: Child process is running
[Fri Nov 09 18:49:39 2012] [notice] Child 7120: Acquired the start mutex.
[Fri Nov 09 18:49:39 2012] [notice] Child 7120: Starting 250 worker threads.
[Fri Nov 09 18:50:03 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Fri Nov 09 18:51:47 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 09:14:30 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/popunder.js, referer: http://crazyufcvideos.net/
[Sat Nov 10 11:38:10 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 12:56:45 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/popunder.js, referer: http://crazydancemus....net/?subid=s17
[Sat Nov 10 14:34:30 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 14:34:36 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 14:34:50 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 17:19:41 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/popunder.js, referer: http://crazyamazingf...info/?subid=v47
[Sat Nov 10 17:27:29 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:27:29 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:27:52 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:27:53 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:28:23 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:28:23 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:28:30 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:28:53 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:28:58 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/scrape
[Sat Nov 10 17:29:03 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:29:30 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:29:48 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:30:03 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:30:13 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:30:13 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:30:48 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/announce
[Sat Nov 10 17:54:09 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sat Nov 10 17:54:15 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
Installing the Apache2 service
The Apache2 service is successfully installed.
Starting the Apache2 service
The Apache2 service is running.
] pid file C:/Program Files (x86)/Apache Group/Apache2/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sun Nov 11 10:05:04 2012] [notice] Apache/2.0.64 (Win32) configured -- resuming normal operations
[Sun Nov 11 10:05:04 2012] [notice] Server built: Oct 18 2010 01:36:23
[Sun Nov 11 10:05:04 2012] [notice] Parent: Created child process 2496
[Sun Nov 11 10:05:04 2012] [notice] Child 2496: Child process is running
[Sun Nov 11 10:05:04 2012] [notice] Child 2496: Acquired the start mutex.
[Sun Nov 11 10:05:04 2012] [notice] Child 2496: Starting 250 worker threads.
[Sun Nov 11 10:05:20 2012] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun Nov 11 10:05:20 2012] [notice] Child 2496: Exit event signaled. Child process is ending.
[Sun Nov 11 10:05:21 2012] [notice] Child 2496: Released the start mutex
[Sun Nov 11 10:05:22 2012] [notice] Child 2496: All worker threads have exited.
[Sun Nov 11 10:05:22 2012] [notice] Child 2496: Child process is exiting
[Sun Nov 11 10:05:22 2012] [notice] Parent: Child process exited successfully.
[Sun Nov 11 10:05:33 2012] [notice] Apache/2.0.64 (Win32) configured -- resuming normal operations
[Sun Nov 11 10:05:33 2012] [notice] Server built: Oct 18 2010 01:36:23
[Sun Nov 11 10:05:33 2012] [notice] Parent: Created child process 5248
[Sun Nov 11 10:05:33 2012] [notice] Child 5248: Child process is running
[Sun Nov 11 10:05:33 2012] [notice] Child 5248: Acquired the start mutex.
[Sun Nov 11 10:05:33 2012] [notice] Child 5248: Starting 250 worker threads.
[Sun Nov 11 10:15:44 2012] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun Nov 11 10:15:44 2012] [notice] Child 5248: Exit event signaled. Child process is ending.
[Sun Nov 11 10:15:45 2012] [notice] Child 5248: Released the start mutex
[Sun Nov 11 10:15:46 2012] [notice] Child 5248: All worker threads have exited.
[Sun Nov 11 10:15:46 2012] [notice] Child 5248: Child process is exiting
[Sun Nov 11 10:15:46 2012] [notice] Parent: Child process exited successfully.
Installing the Apache2 service
The Apache2 service is successfully installed.
Starting the Apache2 service
The Apache2 service is running.
ce] Apache/2.0.64 (Win32) configured -- resuming normal operations
[Sun Nov 11 10:15:50 2012] [notice] Server built: Oct 18 2010 01:36:23
[Sun Nov 11 10:15:50 2012] [notice] Parent: Created child process 3908
[Sun Nov 11 10:15:50 2012] [notice] Child 3908: Child process is running
[Sun Nov 11 10:15:50 2012] [notice] Child 3908: Acquired the start mutex.
[Sun Nov 11 10:15:50 2012] [notice] Child 3908: Starting 250 worker threads.
[Sun Nov 11 10:50:56 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/popunder.js, referer: http://crazyawesomes....com/?subid=s42
[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: first.pl
[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: C:/Program Files (x86)/Apache Group/Apache2/cgi-bin/first.pl
[Sun Nov 11 11:09:00 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sun Nov 11 11:09:29 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/first.pl
[Sun Nov 11 11:09:29 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sun Nov 11 11:09:37 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
[Sun Nov 11 11:11:08 2012] [error] [client 127.0.0.1] File does not exist: C:/Program Files (x86)/Apache Group/Apache2/htdocs/favicon.ico
Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 02:07 PM

OK, these seem to be the relevant lines.

View PostPlanet Telex, on 11 November 2012 - 07:46 PM, said:

[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: first.pl
[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: C:/Program Files (x86)/Apache Group/Apache2/cgi-bin/first.pl


I didn't note this before, because I am so used to running Apache on Linux rather than Windows, but your Perl script starts with the typical executable path for Unix:
#!/usr/bin/perl


This would cause an error like that on a Windows system. Try either removing this line completely, or replacing it with the path to the Perl executable on your Windows machine. For example, if Perl is installed at "C:\perl", you'd probably want to use:
#!/perl/bin/perl


(If that doesn't make sense, keep in mind that the actual executable is at "bin/perl" inside the Perl installation dir.)

I've never used Perl as a CGI scrip on Windows, so I've never actually tried this, but it should work. You may have to do some trial and error to get the path right though.
Was This Post Helpful? 1
  • +
  • -

#10 Planet Telex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-November 10

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 04:43 PM

View PostAtli, on 11 November 2012 - 02:07 PM, said:

OK, these seem to be the relevant lines.

View PostPlanet Telex, on 11 November 2012 - 07:46 PM, said:

[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: first.pl
[Sun Nov 11 11:08:59 2012] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: C:/Program Files (x86)/Apache Group/Apache2/cgi-bin/first.pl


I didn't note this before, because I am so used to running Apache on Linux rather than Windows, but your Perl script starts with the typical executable path for Unix:
#!/usr/bin/perl


This would cause an error like that on a Windows system. Try either removing this line completely, or replacing it with the path to the Perl executable on your Windows machine. For example, if Perl is installed at "C:\perl", you'd probably want to use:
#!/perl/bin/perl


(If that doesn't make sense, keep in mind that the actual executable is at "bin/perl" inside the Perl installation dir.)

I've never used Perl as a CGI scrip on Windows, so I've never actually tried this, but it should work. You may have to do some trial and error to get the path right though.



Thanks man now it works! Now off to try and run one in C++.
Was This Post Helpful? 0
  • +
  • -

#11 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: Viewing CGI files with Apache

Posted 11 November 2012 - 04:44 PM

** Moved to Web Servers & Hosting **
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1