Forum Moderators: coopster & phranque

Message Too Old, No Replies

Installing a Perl script

Need Serious Help

         

davewray

4:02 am on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone. Well, I finally found a script that will count outgoing clicks and will increment it on my site automatically. Problem is, I've installed it and it won't work! I'm going to do my best to describe my situation...

The readme.txt file told me to download the cgi scripts to this path: #!/usr/bin/perl

Now, this is my first question. I can get all the way to: #!/usr/bin, but then "perl" is NOT a folder, but a file. Does this mean I need to right click on that "perl" file and upload my CGI scripts that way, or can I just upload them into the "bin" folder?

What I did was upload my cgi scripts to the bin folder...which is where I think the problem is coming in.

Anyway, it could be how I've scripted the code right on my page? Here's a sample of the code I have on my web page:

<!-- Start of code:

<a href="http://www.advertiser-site.com/#!/usr/local/bin/clickmanager.cgi?dl=http://www.mydomain.com">AnchorText</a>
<!-- This is where classified text goes --><br>
[Hits: <!-- #include virtual="/#!/usr/local/bin/clickmanager.cgi?num=http://www.advertiser-site.com/" -->]

End of Code -->

The "Hits" part above is where I want the number to increment everytime my advertiser's site is clicked on. Can any of you see where I'm flawed in this script...Or perhaps the path where I've uploaded my CGI scripts? Thank-you so much for your time! I hope that someone knows enough about scripts that they can help me! Thanks :)

Dave.

jdMorgan

4:47 am on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



davewray,

I think you may have misread those instructions:

> The readme.txt file told me to download the cgi scripts to this path: #!/usr/bin/perl

That text, "#!/usr/bin/perl" is the "standard" opening line of any PERL script, and tells the scripting parser where to find the PERL interpreter. If for some reason you had a non-standard setup, you would have to change that to point to the PERL interpreter's actual location, for example, "#!/usr/local/bin/perl".

So, you should be able to install your downloaded scripts wherever you want to, provided that the links from your html pages and the references from one script in the package to another are all correct and consistent.

That's really all I can contribute, I'm afraid.

HTH,
Jim

mack

5:24 am on Jul 20, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



As jdmorgan pointed out #!/usr/bin/perl is usualy the opening line of a perl code. It's purpose it to point out the location of the perl intercepter. this will usualy be #!/usr/bin/perl or #!/usr/bin/local/perl.

If you are unsure you can run "whereis perl" from a shell if you have shell access.

Generaly cgi-scripts can be placed anywhere in your server so long as you referance the locations correctly. Usualy you create a folder to hold the script, or one to hold all your cgi scripts for example cgi-bin.

Hope this is of some help.

Mack.

davewray

3:15 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! So, in my cgi script above do I keep the "#!/usr/bin/perl" in there, or do I replace that with the path where I uploaded my cgi scripts? ie. Let's say I upload my cgi script to "cgi-bin"...would I replace "#!/usr/bin/perl" with "cgi-bin"? Thanks again :)

Dave.

ncw164x

3:34 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No you keep #!/usr/bin/perl as it is, some where on the script you should see path and this is where you put the full server path to the script. eg./usr/local/bin/clickmanager.cgi

Like jdMorgan said your path to perl could be #!/usr/bin/perl or #!/usr/local/bin/perl, you will get is a server error if it's the wrong one. Don't forget to chmod the script to 755 or it won't work and you will get another server error

jdMorgan

3:35 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Davewray,

No, you only change that "#!/usr/bin/perl" line if the PERL interpreter for your hosting account is installed in a different location from what that line specifies. Contact your host if you don't know where it is.

You can upload your scripts to any location you like, as long as your pages link to them at that location, and as long as any links the scripts have to each other specify that location.

Your html pages call (link to) the scripts. The scripts "call" the PERL interpreter at /usr/bin/perl, or whatever location is specified in the first line of the scripts. And the scripts may call each other, too (using directives like #include or require). You may have to read through the scripts to find out, if the documentation is unclear or muddled.

HTH,
Jim

ShawnR

4:12 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To make it easier to understand, here is a run-down of what happens:
  • Your webpage tells the visitor's browser which page to ask for. So in your webpage, the cgi script should look like a web url (except with .cgi or .pl at the end instead of .html (e.g. [domain.com...]
  • If the page requested is a cgi script, then your webserver (e.g. Apache) knows that by a combination of things, but the subdirectory is the main one.
  • The webserver then runs the cgi, gets the result, and passes that back to your browser as an html file. To know how to run the cgi, your webserver uses the hash-bang line (among other things)

So....

"...Generaly cgi-scripts can be placed anywhere ..."

I'd suggest you put the script in your cgi directory. Your host should tell you what that is, but it should be something like cgi-bin under your main webpages directory (so, for example, the url to it would be [mydomain.com...]
)

I guess it is true that the script "can be placed anywhere in your server so long as you referance the locations correctly", but you would also have to tell the webserver (e.g. in Apache's htconfig) if you changed the location of the cgi files.

The hash-bang line should stay as #!/usr/bin/perl unless your host has perl installed to a different location, as others have written.

ncw164x wrote that "...some where on the script you should see path and this is where you put the full server path to the script...". I'd change the 'should' to 'may'. It may be true, but a well written script should not require that, so that may not be required.

Shawn

ncw164x

4:35 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your right Shawn it should be "may"

It's only after I posted I noticed that comment, I run over 60 scripts from my site, some have the path on the script and others reference a config file where all the details are placed

I also have scripts where you just reference it via http:// mydomain dot com/cgi-bin/nameofscript.cgi

It all depends on as you say how the script is wrote

davewray

9:57 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh my goodness, I think I'm even MORE lost now! :) This is my understanding so far. Keep the above script in my first post AS IS, in other words, Do not change it. (ie. KEEP #!/usr/local/bin/clickmanager.cgi as is) IF that is the case, HOW does the program know where to read the script from given that I can upload my cgi scripts anywhere (preferrably cgi-bin folder)? What I'm confused about is that if I don't change the path above (#!/usr/local/bin/clickmanager.cgi), how does the program know to retreive the script from cgi-bin?

bunltd

10:07 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Hi davewray.

It looks like you've got your paths confused.

Basically you have two kinds of paths:
one type is relative to the file system on the server
one type is relative to the document root for the web server

The #!/usr/bin/perl tells the script where to find Perl to do it's work.

Your links for using the script, the html part has

<a href="http://www.advertiser-site.com/#!/usr/local/bin/clickmanager.cgi?dl=http://www.mydomain.com">AnchorText</a>

when this path should be relative to document root on the web server, or something like this:
http:*//www.advertiser-site.com/cgi-bin/clickmanager.cgi

So you'll want to upload the script to your cgi-bin folder, and you should be good to go.

Hope this helps.

LisaB

[edited by: bunltd at 10:08 pm (utc) on July 20, 2003]

TheWhippinpost

10:08 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



This is how I think the code should read
<!-- Start of code: 

<a href="http://www.advertiser-site.com/bin/clickmanager.cgi?dl=http://www.mydomain.com">AnchorText</a>
<!-- This is where classified text goes --><br>
[Hits: <!-- #include virtual="/bin/clickmanager.cgi?num=http://www.advertiser-site.com/" -->]

End of Code -->


Assuming of course that there is such a folder on your server called "bin" - You sure it isn't called "cgi-bin"? - If there is a folder called "cgi-bin" rename the "bin" in the code above to..."cgi-bin".

Upload the "clickmanager.cgi" file into the "bin" folder, or "cgi-bin" if it's called that.

That's my take on it anyway

jdMorgan

10:08 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



davewray,

You *do* have to change that include link in your first post to


[Hits: <!-- #include virtual="/usr/local/bin/clickmanager.cgi?num=http://www.advertiser-site.com/" -->]

assuming that you have put your counter script in your [yourdomain.com...] subdirectory,
and you *don't* have to change the #!/usr/bin/perl invocation in the script itself.

I think the problem is simply one of terminology and unfamiliarity. The process of how your pages call the script and where you can put your scripts has been pretty well defined above, I think.

I suggest you try this on a "test" html page, and experiment with it till it works, then put the links/includes on your public page(s) after testing.

Jim

davewray

10:52 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I beleive I understand now. I will try this out on a "test" page to see how it works. I think you're right, I was getting confused with the terminology. Who knows, once I become more familiar with scripts and how they work, maybe I'll be helping someone else out in the future too :) Thanks to everyone for their help!

Dave.

jdMorgan

11:05 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dave,

Yup! The first one is always the hardest - No doubt about it.
Especially since everyone's server is always set up "just a little" different.

Best,
Jim

ShawnR

6:24 am on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh my goodness, I think I'm even MORE lost now

I'm sure I speak for all when I say that was not the intent, and sorry anything we posted caused that feeling.

You *do* have to change that include link in your first post to
[Hits: <!-- #include virtual="/usr/local/bin/clickmanager.cgi?num=http://www.advertiser-site.com/" -->]
assuming that you have put your counter script in your [yourdomain.com...] subdirectory

Well, it is possible to configure a webserver to have its cgi-bin directory be called "usr", but it would be a very unusual non-standard configuration. What is relevant is not just that you "...put your counter script in your [yourdomain.com...] subdirectory...", but also that your webserver knows to treat files in that subdirectory as cgi. So it would be better to put the file in the cgi-dir or cgi-bin or whatever is set up on your site for cgi, as TheWhippinpost suggested.

Shawn

jdMorgan

6:38 am on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, my main point was that this wasn't going to work:
http://www.advertiser-site.com/#!/usr/local/bin/clickmanager.cgi

Jim

davewray

10:47 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone,

Thanks for your help! I changed everything to exactly the way you said I should...still does not work :( When I type in "http://www.mydomain.com/cgi-bin/clickmanager/stats.cgi" into a browser I get a 404 error message! Yet, that is the EXACT location that I uploaded my cgi files to. I've even Chmod them to the right "permission" numbers too. I'm a little stumped I guess :(

Dave.

ncw164x

11:18 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have downloaded the program which you are using and installed it, everything is working OK

I have sticky mailed you the link

ShawnR

11:24 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jdMorgan suggested getting things working with a really simple test page first. Here is another thread which explains how to install a really simple test cgi script:
[webmasterworld.com...]

Shawn

oilman

11:28 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> I'm a little stumped I guess

have you double checked the path to perl for your server? While it's true that #!/usr/bin/perl is a valid path to perl I've seen some hosts that have it in a different place.

Also - you are using a server side include call to run the script - is your server set up to handle SSI? Does your test page have .shtml as the page extension? Most servers aren't set to handle SSI on just any page - it usually has to be .shtml. There are other ways to do it but for now lets just make sure you're using .shtml.

<edited for unbelievably bad grammer ;)>

claus

11:40 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



davewray:
>> When I type in "http://www.mydomain.com/cgi-bin/clickmanager/stats.cgi"

In dealing with these things, a lot of accuracy is needed. These two paths are not the same:

  1. http://www.mydomain.com/cgi-bin/clickmanager/stats.cgi
  2. http://www.mydomain.com/bin/clickmanager.cgi

If you have uploaded the script to a location as in (2) with the name "clickmanager.cgi", you will of course get a 404 (document not found) when trying the first address (#1).

/claus

<edit>
A 404 is easy: It simply means that the server cannot find the file. Servers are normally not wrong about this (although they can be convinced to make mistakes on purpose, but that's something else). I see you say it is the exact location. But you have two files, right? a html file and a cgi file? The html file must have a name ending in "shtml", not "htm", "html", or "cgi".

The html file calls the script, and the html file assumes that the script is stored at location (#2) - that's the location the others have suggested to you, so i guess that's what you have written in it. Try either changing the address to the script in the html-file or storing the script at location (#2) and _then_ entering the address of the html file into your browser (as saved with an "shtml" extension).

Hope this makes some sense to you, it's really not that difficult, it's just that a lot of things can be done in a lot of different ways.

</edit>

davewray

2:14 am on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I checked out the path to Perl. This is it. First I clicked on the usr folder, then clicked on the bin folder. Within the bin folder was the PERL FILE. So, does that make the path: #!/usr/bin/perl OR #!/usr/bin?

I have another query. I have created a cgi-bin folder in my ftp program. Now, I uploaded all the appropriate cgi,txt and pm files to a clickmanager folder. Thus, my path to that would be: /cgi-bin/clickmanager/ right? So, why is it when I type: [mydomain.com...] into my browser my server says it does not exist? And yes, it is the correct path I've typed into my browser...that has really perplexed me.

Dave.

davewray

5:47 am on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I figured it out! FINALLY! :) Now get this, this will blow your mind. Ok, my own created cgi-bin did NOT work. Guess where I finally found it? This was the path: usr/local/apache/cgi-bin Good grief! No wonder I was running around like a chicken with my head cut off! And get this, to view my stats, I don't type: "http://www.mydomain.com/usr/local/apache/cgi-bin/stats.cgi" into my browser, just "http://www.mydomain.com/cgi-bin/stats.cgi". Why is that? Thank you all for your patience and help :)

One more thing though. For some reason, even though on my stats.cgi page it shows me how many hits a certain URL is getting, it isn't actually incrementing on my html page? I'm using the "include" command and it looks like this:
"<!--#include virtual="/cgi-bin/clickmanager.cgi?num=http://www.url.com" -->

So that each time www.url.com is clicked on I want a physical increment to be seen on my page beside this URL so that other visitors can see it. Any suggestions? Thanks again!

Dave.

claus

11:21 am on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great news Dave :) The path to your cgi-bin is probably being rewritten with an internal rewrite rule, it is quite ordinary that you will se another path in the browser than the path you have in your own file system (one more of those things that make it all seem a bit complicated).

The HTML-thing:
Try changing the file-name from "file.html" to "file.shtml" - this sounds crazy, but it has some importance in some cases.

Both things (settings for paths and file-extensions) can be changed. It seems like you have something like root access, so you might have the necessary priviledges to do it. On the other hand, if we can get it to work for you as it is now there's no need to change it ;)

/claus

ShawnR

12:11 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"...On the other hand, if we can get it to work for you as it is now there's no need to change it..."

Just to add... It is very important that you don't change it. Claus is correct that this is quite ordinary. In previous posts I tried to explain that your webserver needs to know where the pages (html and cgi) that you are serving are referenced from. This is important for security. You are giving your visitors access to pages under that "html root" directory. You definitely don't wan't that to be your root directory so your visitors can get to anything in your e.g. usr directory. You only want to allow your visitors access to cgi scripts in your cgi-bin directory. Does that make sense?

Shawn

davewray

6:03 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shawn,

I was actually thinking about security the other day. Being new to this I'm totally exposed due to ignorance! So, what is it I should NOT change? Is it ok to change my file extensions to .shtml on pages I'm trying to use SSI? What exactly would allow my visitors access to my usr folder? Again, thank you all for your great help! This is what makes WW so awesome :)

Dave.

claus

8:31 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dave, it's okay to change your file extensions from html to shtml.

Security risks.. I do not believe ShawnR was referring to changing the file-extensions of specific html-pages here. This is not a risk.

I think he wanted to draw your attention to the fact that it is very important to know exactly which folders and files you want to make accesible by the public and which you want to keep private. With your structure this implies that stuff in, say,

usr/local/apache/

...is probably okay, as that is your domain root. On the other hand, a random web user should not be allowed to access other folders on the same level as "apache" or higher. Perhaps there's even some stuff in /apache/ or below that should be restricted, this all depends on your setup.

It's a little difficult to give general advice on these topics, as server setups are rarely 100% similar. On the other hand, please don't post any more details to the public (this forum can be read by anyone), consult someone you know personally or professionally in stead.

/claus

ShawnR

10:07 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I was refering to the paths/directory structure, not the file extensions.

davewray

11:26 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, how would I keep visitors/users from accessing folders that I don't want them to have access to? Thanks :)

Dave.

davewray

5:39 am on Jul 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmmm...when it seems like I've finally made it "there" I always come across something that still doesn't work! I can't get the script to physically add the number of clicks a certain url is getting. It'll show up in my stats program, but it won't show on my web page. I've changed the page to an .shtml file too...This is what the code looks like:

<!--#include virtual="/cgi-bin/clickmanager.cgi?num=http://www.urltocount.com" -->

*Do I need the "<!--" at the beginning and end for this to work? Or is this what is causing the problem in the first place?

Should I use this alternate line of code instead? :

<!--#include virtual="/cgi-bin/clickmanager.cgi?numall=1" -->

Thanks for your help :)

Dave.

This 34 message thread spans 2 pages: 34