Forum Moderators: coopster & phranque

Message Too Old, No Replies

Using Apache to test CGI Scripts

         

lisad

1:39 am on May 21, 2003 (gmt 0)

10+ Year Member



I have Apache installed and running on my system, but what exactly do you do with the .cgi file and the .html file that calls the .cgi file?
Is there a specific line of code at the beginning of the .cgi file? Is there a specific place you are supposed to put the .html file?
When I open the .html file locally and try to run the .cgi file, it just tries to open it, not to run...

Does anyone know enough about this to help me?

BCMG_Scott

12:34 pm on May 21, 2003 (gmt 0)

10+ Year Member



In httpd.conf you will have a DocRoot value defined.
DocRoot /path/to/your/website

Place your HTML file inside that DocRoot directory. For CGI you probably have a ScriptAlias setting:

ScriptAlias /cgi-bin/ /path/to/your/cgi-bin/

place your cgi file in the /path/to/your/cgi-bin/. Make sure that the file is marked executable.

your URL to the HTML file would be:
[somedomain.com...] (or [127.0.0.1...] if you are running it locally and have not played with your hosts file).

For the cgi:
[somedomain.com...]

Scott Geiger

lisad

5:54 pm on May 21, 2003 (gmt 0)

10+ Year Member



DocRoot is in the conf folder?

lisad

5:55 pm on May 21, 2003 (gmt 0)

10+ Year Member



(in the httpd.conf file)

lisad

6:00 pm on May 21, 2003 (gmt 0)

10+ Year Member



Also, how do you make the cgi file executable when you're not using unix?...I'm using windows.

BCMG_Scott

6:51 pm on May 21, 2003 (gmt 0)

10+ Year Member



yes DocRoot is in httpd.conf. I think I remember you mentioning that you were running windows - was it 2000 or XP? Either way you should be able to right click on the file and choose properties. There should be a security tab. The permissions that you should have are "Read" and "Read & Execute".

Scott Geiger

lisad

6:57 pm on May 21, 2003 (gmt 0)

10+ Year Member



I'm using XP Pro. But on the security tab it just shows who has access to the file.

lisad

6:58 pm on May 21, 2003 (gmt 0)

10+ Year Member



Also, I have full control.

mat

9:00 am on May 22, 2003 (gmt 0)

10+ Year Member



We run Perl locally (Win2K) to test cgi scripts - do a Google search for 'Active State Perl' and get the free download that you need from there.

lisad

12:51 pm on May 22, 2003 (gmt 0)

10+ Year Member



I have Perl Activestate, but when I run the file using perl, it just prints out the coding.

mat

1:12 pm on May 22, 2003 (gmt 0)

10+ Year Member



At this point you're probably going to have to post some code (minus site specific stuff) from the page concerned showing just how you're calling the script.

lisad

1:23 pm on May 22, 2003 (gmt 0)

10+ Year Member



This is how I'm calling the script from the HTML file:
___________________________________________________________
<img src="../images/cblogonew.jpg" width="118" height="51">
<form action="C:/Apache/cgi-bin/homeFlites.cgi" method="post" >
___________________________________________________________

the HTML file (default.htm) is in C:/Apache, and the cgi file (homeFlites.cgi) is in C:/Apache/cgi-bin.

TheWhippinpost

1:44 pm on May 22, 2003 (gmt 0)

10+ Year Member



Hi lisad

My eyes are stingin like hell today for some reason so I've briefly read as best I can.

Try calling pages using

http://localhost/

<form action="http://localhost/cgi-bin/homeFlites.cgi" method="post" >


Also, you should have a directory called htdocs, place your html pages in there.

HTH

mat

1:57 pm on May 22, 2003 (gmt 0)

10+ Year Member



Haven't done this for a long while, so I hope I'm not sending you in the wrong direction, but when I was testing locally I'd change the path to Perl (usually the first line of the script, probably /usr/bin/perl) to c:\Perl\bin\Perl5.6.0.exe or whatever.

Of course you've probably done this, and/or this is absolutely the worst thing to do, but, hey, it worked for me!

BCMG_Scott

7:18 pm on May 22, 2003 (gmt 0)

10+ Year Member



I think TheWhippinpost has it, you need to let Apache handle the CGI request so that it will use the perl-handler (per module). Otherwise it just gets served up as text/html. Also be sure that you have ScriptAlias defined for that path.

Scott

Brett_Tabke

4:54 am on May 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Ok, let me skip all the way back up to the beginning and address only lisa's first post. Here is what I do:

First, set up your local directories to mirror just how your site is setup. If you website is store on your host in:

/home/foo/mysite

Then go to your C: drive and create that path and place all your website files in that directory just as they are stored on your hosts drive.

That will become your DocRoot as other described above.

That also means once you are into running cgi's you won't have to muck with changing any paths in those cgi's in order to upload them.

ShawnR

12:16 pm on May 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good idea, Brett.

Lisa, to make sure perl is installed correctly and your webserver is configured correctly to associate perl cgi scripts with the perl executable, I'd suggest the following:

Copy and paste the following lines into a file (call it say test.pl)

#!/usr/bin/perl
print "Content-Type: text/HTML\n\n";
print "Hello, World<p>\n";

(don't worry that the path to perl on your windows machine is not /usr/bin/perl ...)

Store the file in your cgi-bin directory (e.g. C:/Apache/cgi-bin/ or whatever it lands up being after you have followed Brett's excellent suggestion)

Now run that file from a dos prompt as follows:
perl C:/Apache/cgi-bin/test.pl

You should get:

Content-Type: text/HTML

Hello, World<p>

OK, good, so now you know perl is set up and working correctly. Now point your browser to [localhost...] Your browser should show:

Hello, World

Now you know that perl is set up correctly and your web server is set up correctly to serve perl cgi.

So any other problems are probably in your html files calling the cgi, not in your configuration. In particular, I think TheWhippinpost hit the nail on the head. C:/Apache/cgi-bin/homeFlites.cgi is just a file that your browser will fetch from your C: drive and display, and your web server won't get involved at all. However, [localhost...] will cause your webserver to send the script to perl for processing, and send your browser the result.

how do you make the cgi file executable when you're not using unix?...I'm using windows

You don't have to. You run perl scripts as an argument to the perl executable. So in Windows its just a text file as far as perl is concerned.

Shawn

lisad

2:24 pm on May 26, 2003 (gmt 0)

10+ Year Member



When I point my browser to [localhost...] not only does it not show Hello World, but it gives me:

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, @@ServerAdmin@@ 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.

--------------------------------------------------------------------------------

Apache/1.3.26 Server at localhost Port 80"
__________________________________________________________

But running the perl script using perl worked fine.

ShawnR

3:41 pm on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, here's what you got to do: contact the server administrator, @@ServerAdmin@@ and inform them of the time the error occurred. Oops, that is you. OK, then on to plan B:

Look in Apache's error logs for clues.

Just guessing here, but perhaps your Apache doesn't know the path to perl. Make sure that you have the path to perl defined correctly, and that your windows file associations are correct. i.e:

-> Control Panel
-> Folder Options
-> File Types tab
-> Scroll down to PL
-> click 'advanced'
-> click 'open, then click Edit
-> you should something like ""C:\Perl\bin\perl.exe" "%1" %*

You should be able to configure it to correctly run perl even though the path to perl is not correctly specified in the!# line. The advantage of this is that your scripts are portable to linux servers. However, just to check if this is the problem, try changing the first line in the file to:

#!C:\PERL\5.00464\bin\MSWin32-x86\perl.exe

(or whatever the path to perl is)

Sorry I can't give anythign definitive.

Shawn

lisad

3:43 pm on Jun 9, 2003 (gmt 0)

10+ Year Member



wtf... I don't have a "PL" in folder options -> file types!

AAAAHHH!

ShawnR

11:21 pm on Jun 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could create it by pressing the 'new' button when in the 'file types' tab. However, I am surprised, as the ActivePerl install process should have done it for you, so maybe your perl installation didn't work properly. Perhaps try to install perl again.

Shawn

TheWhippinpost

8:58 am on Jun 12, 2003 (gmt 0)

10+ Year Member



Any luck on this yet Lisad? If you pull up the dos window and type: path
What does it say?

Birdman

11:04 am on Jun 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I'm working on getting Apache running also. I put the important(I think) directives below. I have tried port 80 as well. When installing, I read that Apache would not share a port if it was already in use by another service. That's the port my cable modem is using, I believe. I also changed DocRoot, as Brett said, to mirror my real host's server.

Anyhow, I would greatly appreciate any advice.


ServerRoot "C:/Program Files/Apache Group/Apache2"
Listen 8080
ServerName username.******01.md.comcast.net:8080
UseCanonicalName Off
DocumentRoot "C:/home/user/public_html"
<Directory "C:/home/user/public_html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "C:/home/user/public_html/cgi-bin/"
<Directory "C:/home/user/public_html/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

Birdman

11:10 am on Jun 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh yeah, I'm getting "could not connect to remote server".

ht*p://localhost/

Thanks!

rharri

11:59 am on Jun 12, 2003 (gmt 0)

10+ Year Member



You might also try running perl with the "-w" switch when you're testing scripts to give more warnings. Your scripts might be running by hand in spite of a problem.

Bob

Birdman

12:21 pm on Jun 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, now I have successfully connected, but I'm stuck at the same spot as Lisa. No matter how I write the path, it just spits the code out to the browser.

Typing "path" in DOS prompt give me this path:

C:\PERL\BIN\

I've tried every combination of uppercase-lowercase, forward-backward slashes and no ending slash.

Also, I can't find "Folder Options" in the control panel.

Sorry for hijacking your thread, Lisa :)

lisad

4:11 pm on Jun 12, 2003 (gmt 0)

10+ Year Member



The Whippinpost:

When I type path from the dos prompt, I get this information:

"PATH=c:\PROGRA~1\Borland\CBUILD~1\Bin;
C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Nortel\CALLPI~1\bin;
C:\Nortel\CALLPI~1\boin\win32"

[edited by: jatar_k at 8:07 pm (utc) on June 12, 2003]
[edit reason] split line on semicolon to stop sidescroll [/edit]

TheWhippinpost

5:51 pm on Jun 12, 2003 (gmt 0)

10+ Year Member



BIRDMAN: You say it's spitting code out to the browser, I assume you mean code text? I'd check to see if Apache is actually "switched on" IYSWIM

LISAD: It looks like something is amiss with the installation. You should see something similar to Birdman's path above.

My path reads "C:\Perl\bin;C:\Perl\site\lib;C:\Perl\lib;" You could try and open up the AutoExec.bat file in a text editor and add the entry if you want (without quotes, check the paths on your system and adjust) but I'd re-install if I were you.

Birdman

7:43 pm on Jun 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello again, I believe Apache is on, because it is serving my pages, but I keep getting "Forbidden" errors when trying to run a script.

I've been searching for a way to change permissions on win 98, but can't find anything. Do I need to add some sort of utility, like a cpanel to do this?

Thanks again!

TheWhippinpost

8:55 pm on Jun 12, 2003 (gmt 0)

10+ Year Member



Hi Birdman.

If you click on START/PROGRAMS/ACCESSORIES/SYSTEM TOOLS/SYSTEM INFORMATION

In the left pane of the window that opens, click on SOFTWARE ENVIRONMENT/RUNNING TASKS

In the list on the right, you should see Apache.exe

If you want to sticky me I'll try and help further. You shouldn't need to set up permissions on Win 98 installation.

This 32 message thread spans 2 pages: 32