Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Do .cgi-files need to be compiled? My impression has been that writing the script (say in Perl) in f ex Kate should do the trick, but whatever I do the file is still represented by a screw-driver instead of a cog-wheel. The system calls it Perl-program instead of executable file and then I have changed the rights for the file and performed a
chmod a+x /pathway/echotest.cgi
I have also tried to copy the file to every cgi-bin on my computer without any results and the browser will list the contents of the scriptfile instead of running it (or is that the CGI passing it to the browser?) I know listing long scripts is not a favourable thing to do, but it's the only way I know for the moment, so here goes.
I'm running Red Hat 9.0
The script:
#!/usr/bin/perl
use CGI;
print CGI::header();
my %form_data = CGI::Vars;
print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE>";
print "Results for: ",$in{'name'};
print "</TITLE></HEAD><BODY>";
print "<H1>Just for You</H1>";
print "<P>Hi ",$in{'name'}," !\n";
print "<HR>";
print "<P>You live at ",$in{'address'};
print "<P><STRONG>Is this correct?</STRONG>";
print "<P>Homebrewer? Lessee...",$in{'hb'};
print "<P>You like homebrew!" if $in{'hb'} eq 'Yes';
print "</BODY></HTML>";
The latest link in the html doc:
FORM ACTION="file:/var/www/html/echotest.cgi" METHOD="post"
the .cgi-file and html code was saved in winsami2 encoding.
Last, but not least: A big thanks to "spooon" and "chrism01" for your answers to my earlier question on getting CGI up and running in the first place. You are life-savers.
Have I mentioned that the html code is wrtten with Kate too and works fine. So does the script as long as I'm running it from the Terminal, but it can't stop there, can it?
You do know you have to adjust the Apache httpd.config file for script aliases, so Apache (!) recognises it as executable?
WTF is winsami2 encoding ? What's wrong with good old ASCII text (for Perl anyway)?
FORM ACTION="file:/var/www/html/echotest.cgi" METHOD="post"
I think I see your problem here.
By calling a "file:/" url, you're telling the computer to look for the link on the local filesystem, and not go via the web server. (I'm assuming you are running a web server? eg Apache)
You want to be accessing all your html pages and cgi scripts with addresses that start with something like "http://localhost/", rather than with "file:/".
So to access your main page (lets assume it's called 'page.html'), you'd enter "http://localhost/page.html" into your browser.
For best results, your links (eg the action=".." link) should also be relative links rather than fixed links, so if the cgi file is in the same directory as the html file (which it looks like it is from your example), you'd just write action="echotest.cgi".
Finally, Apache may need to be configured to run CGI scripts in the required directory (this may be disabled, depending on your current setup). If in doubt, use the cgi-bin folder that was there at the beginning.
Yes, or at least I was running one. Only some file got lost all of a sudden (don't ask me how, it's pretty embarrassing) and I had to reinstall Linux. Now I have all sorts of files for Apache - even config programs - but I can't find Apache itself. Before the reinstallation there were HTML-files I could read on how to start it, but they seem to have gotten lost too. Does anyone know the command to start Apache from the terminal? All I can remember is /sbin/ something.
Could it be I have to reinstall it? I did tell Linux to throw in the webserver when I reinstalled, so it really has me puzzled. Or maybe I have to use another Installation type. As for the moment I'm running the type before Server-type that you'd want if your planning to do programming (Red Hat 9.0) if it helpes anyone. What doesn't make sence to me is why it would install half the program, but not all of it. Maybe the installation files are there if you know where to look? Does anyone?
Last question: Does anyone know of a way to reinstall without losing the user account?
Wonderful news on Apache. It turned out to be a documentation problem. After installing the doc-CDs I found the docs concerning turning apache on and off. A new problem arose though: I'm using this HTML-bit
FORM ACTION="http://localhost/var/www/cgi-bin/echotest.cgi" METHOD="post"
and I get a 404 Object not found on this server.
Does any one know how to get around this? The file exists and there are no spelling errors and the rights are set to executable for everyone.
Lots of thanks to the friendly souls that's helped so far, as well as future benefactors.
Tillus
Thanks a lot! Now I actually get a response from the server! There is one thing I can't figure out though. I use the script from my first post, but the server only sends back the HTML-text. All the variables are left blank and when I try to look up the source for the returned dokument, the variables are missing there too, all of them. They aren't in the url (Query string) either. My question is: Can there be something syntactically wrong or is it as simple as turning some option on or off in the browser? With the risk of being long-winded I include the text between the FORM-tags in the HTML:
<FORM ACTION="http://localhost/cgi-bin/echotest.cgi" METHOD="post">
<P>Please enter your name: <INPUT TYPE="text" NAME="name" SIZE=40>
<P>E-mail address: <INPUT TYPE="text" NAME="email" SIZE=60">
<P>Mailing address: <TEXTAREA NAME="address" ROWS=5 COLS=45></TEXTAREA>
<P>Do you make homebrew?:
<INPUT TYPE="radio" NAME="hb" VALUE="Yes" CHECKED>Yes
<INPUT TYPE="radio" NAME="hb" VALUE="No">No
<P><INPUT TYPE="submit" VALUE="Send Info">
The problem with the variables was identified as a porting problem. The header
_________________should be changed to
#!/usr/bin/perl__________________________#!/usr/bin/perl
Require("cgi-lib.pl");_____________________use CGI;
&ReadParse;__________________________CGI::Readparse();
Thus porting it to the newest version of CGI.pm. Thank God for man-pages!
I do have one question though: How do you get linebreaks in the data echoed back from the script (f ex the line breaks in an address)? It is a bit tedious to get one long line for the address.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.