The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.

Things look quiet here. But I've been doing a lot of blogging at because I prefer WordPress now. Not all my posts there are FreeBSD related. I am in the midst of migrating The FreeBSD Diary over to WordPress (and you can read about that here). Once the migration is completed, I'll move the FreeBSD posts into the new FreeBSD Diary website.

Perl scripts that appear in your browser 7 January 2000
Need more help on this topic? Click here
This article has no comments
Show me similar articles
Quite some time ago I added a uptime script to one of my web pages.  Someone wrote in saying that when they used the script, the script contents appeared in their browser instead of the uptime results.  At the time, I had no idea what the problem was.   Now I do.
The symptom
If you follow the directions for the uptime script and then browse to your code, but find that you see this on your browser:
use CGI;
$query = new CGI;
print $query->header('text/html');
print `uptime`

then I'll bet that you browsed to your website without using a virtual host.  I'll bet you browsed to the machine first.  Then into a directory which contained your script.  That is what causes the problem.  Use a URL instead.

An example
Here's an example of the problem. 
  1. Browse to which will give you a directory listing.
  2. Click on the directory.
  3. Click on the uptime link.

You should now be looking at the script mentioned in the previous section.

If you want to see the script working properly, see and click on uptime.

The fix
The solution is to ensure that you are browsing with a virtual host name which corresponds to the cgi-bin directory you are trying to execute.

To be truthful,   I'm not sure of the actual underlying problem, but I think it has to do with ScriptAlias and cgi-bin.  If you know more, please tell me.  I just happened to stumble along on a solution.

Need more help on this topic? Click here
This article has no comments
Show me similar articles