Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling Perl on Apache?

Status
Not open for further replies.

carlosc

IS-IT--Management
Dec 24, 2001
9
US
I'm trying to run a counter script from my linux (mandrak 7) apache web server. I'm pretty much cluless on cgi. I was wondering if there's anything I need to change with the apache conf (or any other files) to get cgi to work.

I created a folder called "cgi-bin" in my html folder where all my web docs are kept, put in the perl script and it does nothing. Even when I access it The script text just comes up. It says to use to get my logs, but I just get the source code for the script again??? Can someone point me in the right direction. Thanks MUCH in adavance.
 
Hi,





To get cgi scripts working you have to put several directives in httpd.conf. They are probably already there commented-out - just remove the # symbols and configure for your setup :





ScriptAlias /cgi-bin/ "/var/





You set this to equate to the physical directory path you have your scripts in..





<Directory &quot;/var/

AllowOverride None


Options ExecCGI


Order allow,deny


Allow from all


</Directory>






You need a directory container for the same path similar to the above..





AddHandler cgi-script .cgi .pl





.. And an AddHandler statement that defines which file extensions will be treated as cgi scripts..





That is the basic setup in httpd.conf. The other things to remember are to make sure the scripts are marked as executable. For example :





chmod +x ipcpounter.pl





I would also change ownership to the 'apache' user (assuming thats the user that apache runs under on mandrake) (as root) :





chown apache.apache ipcpounter.pl





Now, assuming you have perl working in the first place, it should be OK. For basic perl (vs mod_perl) there is actually nothing special really to do vs any other cgi scripts, e.g. bash or whatever. The simplest test perl script you can do is one like this :





#!/usr/bin/perl


#


#


print &quot;Content-type: text/html\n\n&quot;;


print &quot;Test CGI script\n&quot;;






Thats about it.. try it out





Regards
 
On the first line of perl do I need the &quot;!' in #!/usr/bin/perl&quot; ? Thanks ALOT for your help. I really appreciate it. This board has become very helpful. The people are very patient and willing to help out with speedy reasonse.
 
where the cgi files are located locally on machine:

/http/html/cgi-bin/
 
Hi,



Well, I can't see anything obviously missing in your config. Are you sure that perl is installed and working ? Just do this from a shell prompt :



$ perl -version



You should get back version info. Regarding the #!, yes you definitely need that on linux/unix. The reason is that on M$/win the executable to run is determined by association with the file extension. So, if you use .pl and thats associated with a Perl interpreter then it just works. On Linux, however, for the operating system itself (vs Apache) the file extensions are relatively meaningless other than under gnome/kde when you use mime types. You can have a perl script with any extension you like (test.pl, test.cgi, test.abc, test). If the file is marked as executable, the shell looks inside for the #! entry to invoke the relevant script handler. So, if you have #!/usr/bin/perl and your perl is actually at /usr/local/bin/perl it won't work! (On apache you'll get a 500 error). So check your perl path ...



Another thing to try is a bash cgi script - this should prove if you cgi-bin is OK and its just a perl problem. Cut and paste the following and place it in your cgi-bin directory and make executable (chmod +x bashtest.cgi)


#!/bin/bash

echo Content-type: text/html

#The following (empty) line is necessary!

echo

echo '<html>'

echo '<body>'

echo 'It is now '

date

echo '</body>'

echo '</html>'




then do a --> .



Hope this helps
 
Hey, thanks a lot ifincham. I got it working. Stupid me got rid of the &quot;#!&quot; in the first line! I replaced that and it worked! Thanks again. I really appreciate it.
 
Erm, where is the httpd.conf file i need to edit? :p I also have this problem, and unfortunatly this is my first webserver i have ever managed, so i expect you will see more of me soon ;)

Thanks

Andy
 
Hi,



If you are using Linux/Unix then it could be in several places. On Redhat by default it would be :



/etc/httpd/conf/httpd.conf



for an install obtained from apache.org it would be at :



/usr/local/apache/conf/httpd.conf



Otherwise, for rpm based distros, you can probably find httpd.conf's location by doing :



rpm -ql apache | grep httpd.conf



On a win32 install it would be :



C:\Program Files\Apache Group\Apache\conf\httpd.conf



(Obviously C:\ might be different depending on which drive it ws installed)



Regards
 
Ah, thanks for the reply. Just found another way to locate it. Type in

shell> locate httpd.conf

and then it will list all the locations of it :)

Thanks though

Andy
 
Hi,

Hmmm ... true but that assumes you're running periodic 'slocate's on your box. Redhat does that daily via cron by default. Locate is very fast because it reads a database of info gathered during those daily runs. The problem with locate, however, is that you won't get any answer if you only just installed something ! To do that you'd have to use 'find' (takes a lot longer because its actually searching the filesystem ) :

find / -name &quot;httpd.conf&quot;

Good point though....

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top