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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setup default directory at localhost ?

Status
Not open for further replies.

dhossbach

Technical User
Apr 16, 2002
13
0
0
FR
Using mandrake linux 8.1.
Localhost says apache is up and running. Now I would like to test cgi scripts localy.
The question is : how do I setup the directory in order to call the cgi scripts from localhost ?

Thanks for any help.


Detlef Hossbach
(occasional programmer)
 
I use Red Hat so I don't know if your directory structure is the same but you will still get a pretty good idea of what needs to be done. I'n my case, the defailt directories are already created. /var/ and /var/ You should see a section in httpd.conf that says "ScriptAlias /cgi-bin/ "/var/ The ScriptAlias directive does 2 things. First it tells apache to treat everything in that directory as a script. The Alias part says make it look like it is under (inside) the html (DocumentRoot) directory. This way you can type will always be the DocumentRoot and all aliased directories are relative to that. There should be a cgi-bin container already setup. It will look like this:

ScriptAlias /cgi-bin/ "/var/
#
# "/var/ should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory &quot;/var/ AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

If you have that in httpd.conf and the real cgi-bin NEXT to the DocumentRoot, all you need to do is put your scripts in there and it should work. If you make any changes to httpd.conf, you must restat apache so it can read the new changes.
 
ooops forgot that you asked how to access them from localhost. Just type in your browser and you are set. One more thing, if your scripts are more than one file, you may want to put them in their own sub-directory under cgi-bin. All sub-directories will have the same permissions and attributes as the main cgi-bin unless you create a container in httpd.conf just for that dir. Good luck.
 
All the files where located as you explained.
The only difference is that directories are in commonhttpd.conf and not in httpd.conf.
Now the problem is that I have no permissin to access cgi-bin error 403.

Whats needs to be done to change this?

config files can seen at the following links:

Thanks for all the help.

Detlef Hossbach
(occasional programmer)
 
I wasn't able to see the files using the links you gave but if you have the cgi-bin setup correctly, you should just have to set the permissions for that directory. This is done at the system level and not in the apache config files. In some distros of linux apache runs as user = apache and group = apache while in others they are both set to &quot;nobody&quot;. Your system is not letting your server have access to this directory or file so it gives the error. To fix this you need to set permissions for this directory by saying who can read the file or directory, who can write to it and who can execute it. If you type ls -l at the command line, you will see a listing of whatever directory you are in. On the far left it tells you who can do what to the file a &quot;-&quot; means the bit is not set, an &quot;r&quot; means read, a &quot;w&quot; means write and an &quot;x&quot; means execute. It should have 10 spaces filed with one of those letters or a dash. The first space is either a &quot;-&quot; or &quot;d&quot;. if it's a &quot;d&quot; this means it's a directory. It could also be an &quot;s&quot; but we won't go into that right now. The other 9 are for user, group and other with 3 spaces each. Now in the middle of the screen you will see the owner and group. If you created the file as root you will see root in 2 columns. user/owner root and group root. Then the last column is the dir or file name.

You can do 2 things. The first is to change the user/owner and group of all the directories and files or you can change the permissions of the directories and files. In the first case, you would use chown like this:

chown -R apache:apache /var/
The -R will cause cgi-bin and everything below it to change the user:group to apache.

The second and most popular way is to run chmod to just change permissions. The syntax is as follows:

chmod [ugoa] (user, group, other, all) [+-=] (add or remove permission) [filename]

For example:

chmod a+rwx /var/ would give everybody read, write and execute permission in that dir. Chmod can also take a number. This would be the same as the example above:

chmod 777 /var/
Lets say I want to give everybody read and execute permision but only want the owner to have write permission. The number would be 755. Here is how you come up with this number. Read has a value of 4, write = 2 and exec = 1. Imagine a table like this:

|user|group|other|
read=4 | X | X | X |
write=2 | X | | |
exec=1 | X | X | X |

Tatal | 7 | 5 | 5 |

If you have a GUI file manager, you can pretty much forget what I said :)
 
Thanks for all the explanations. They are really usefull since I am relatively new to Linux (4 month). It's hard to get things working, but when they do, they work much better than on Windows.
Now I can call my scripts but Apache returns error 500. My Perl test script works from the command line, it's quite mysterious to me why it won't work on the server.
The links to the conf files above do work ......

Perhaps I need one more thing to configure.

Thanks for your help. Detlef Hossbach
(occasional programmer)
 
Error 500 is a catch-all error code that means something is wrong with the way the server is set up and the request couldn't be fulfilled. You will need to look at your error_log to get more details of what went wrong. If you can't figure it out, post the error(s) here and we can see if we can get ya fixed up.
 
error from the log file:
---------------------------------------------------------
[Sun Jun 16 21:06:59 2002] [error] [client 127.0.0.1] Premature end of script headers: /var/----------------------------------------------------------


and below the simple test script test.pl
--------------------------------------------------------
#!/usr/bin/perl

use CGI;

$query = new CGI;

print $query->header;

print &quot;<html><head><title>test</title></head>\n&quot;;
print &quot;<body>test works</body></html>&quot;;
---------------------------------------------------------- Detlef Hossbach
(occasional programmer)
 
Ok- I see Mandrake uses a lot of .conf files instead of one. Here is what is happening. Apache doesn't know that .pl is the same as .cgi. Rename test.pl to test.cgi to see if this is true. If it works, then look in commonhttpd.conf for a line that says:

AddHandler cgi-script .cgi

and change it to:

AddHandler cgi-script .cgi .pl

This is usually to make it so you can run cgi scripts outside the cgi-bin but it will work in your case. It tells apache to handle anything with a .cgi and .pl extension as a cgi-script. Another option is to add it to /etc/mime.types
 
ok, it's finaly working.
I learned a lot in the past 2 days.
Thanks for your assistance. Detlef Hossbach
(occasional programmer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top