Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

How to run CGIs from the user's Sites folder UNIX
[Editor's note: Submitted by Crusty on July 5th. This question has been asked numerous times in the last month, so I figured I would see if one of the Apache wizards out there can provide the answer for the interested readers...I have an idea of what needs to be done, but not all the details.]

Hello all,

I've recently installed OS X on my Powerbook and love it. The main reason I purchased OS X was so I could work on Web pages that use SSI, Perl, PHP and MySQL without always having to connect to the Internet. I've followed some tutorials on this site about installing Apache, PHP and MySQL, and have them all running properly from my user directory called "Sites"!! I love it. But... I can't get any CGI/Perl scripts or SSI to work properly. I've used the terminal to go into the config file and altered the following lines:
Options Indexes FollowSymLinks MultiViews ExecCGI +Includes
and
DirectoryIndex index.html index.htm index.shtml
and
AddType text/html .shtml
AddHandler server-parsed .shtml
Neither CGI or SSI work in my users "Sites" folder, but PHP and MySQL do. What have I missed? How can I get CGI/SSI to work in my personal site? Any help would be greatly appreciated.
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,424 views]  

How to run CGIs from the user's Sites folder | 11 comments | Create New Account
Click here to return to the 'How to run CGIs from the user's Sites folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
This one hade me thinking for a while
Authored by: Anonymous on Jul 09, '01 01:30:07PM

You need to make the settings in this file for each user "/etc/httpd/users/[username].conf". I haven't seen this solution before (i.e. Debian don't use it) but I quite like it.

Anyone knows where the default settings for this file is coming from? Would be nice to be able to set the default your self.

Regards,
Fredrik Jonsson



[ Reply to This | # ]
httpd.conf
Authored by: Anechoic on Jul 09, '01 01:46:56PM
I did the following, and cgi/Perl scripts word for me in Apache under OS X:
In /etc/httpd/httpd.conf
  1. Uncomment the line "LoadModule cgi_module libexec/httpd/mod_cgi.so"
  2. Uncomment the line "AddModule mod_cgi.c"
  3. Uncomment the line "Options Indexes FollowSymLinks MultiViews ExecCGI"
  4. Uncomment the line "ScriptAlias /cgi-bin/ blah blah" and edit to taste
  5. Uncomment (and edit if desired) the line "<Directory "/Library/WebServer/CGI-Executables">"
Steps 4 and 5 are really the same thing, but step 5 uses Apple's XML configuration, while step 4 uses the standard Apache configuration method. I'm not sure if both are required or if you can get away using only one method. That should be it, HTH Herb

[ Reply to This | # ]
Still not working
Authored by: Crusty on Jul 10, '01 11:47:30AM

Thanks for your suggestions. I've tried altering the individual user's config file, and now SSI works, but CGI/Perl still doesn't. I either get a permissions error or premature end of script headers error (or something like that). I've tried changing the permissions on the files in the Finder, but because the files were created in OS 9, the owner/group is "Staff", and I can't alter them, even though I'm an admin. I guess that's another problem entirely. Gotta get used to the whole permissions spiel now. How can I change the permissions and why am I getting premature end of script header errors when the exact same script works perfectly on a Unix server?



[ Reply to This | # ]
Have you read the Apache FAQ?
Authored by: Erik Toh on Jul 10, '01 09:11:22PM
It's located here.... might help.

[ Reply to This | # ]
Still not working
Authored by: mebigrock on Jul 12, '01 11:12:43AM

perl scripts need to be made executable for apache to run them. a command like the one below should work.

chmod a+rx filename.pl



[ Reply to This | # ]
Still not working
Authored by: Crusty on Jul 12, '01 09:15:03PM
I forgot to mention that I was testing a VERY basic Perl script:
#!/usr/bin/perl
print "Content-type: text/htmlrnrn";
print "Hello, World.";
There are backslashes before each "r" and "n", but they don't show up here. And I still get the errors I mentioned in my earlier post a few minutes ago. I know that's where Perl is on my computer too.

[ Reply to This | # ]
Still not working
Authored by: Crusty on Jul 12, '01 09:04:45PM
I've done everything I can think of now. I've got my Apache config file setup correctly. I've read the Apache docs, I've given permissions, etc. Now I get an internal server error with this in my error log:
[Thu Jul 12 19:47:09 2001] [error] (2)No such file or directory: exec of /Users/crusty/Sites/cgi-bin/test.pl failed
[Thu Jul 12 19:47:09 2001] [error] [client 127.0.0.1] Premature end of script headers: /Users/crusty/Sites/cgi-bin/test.pl
What am I doing wrong now? I'm getting amazingly frustrated with this now. On top of this problem, I had a new hard drive put in, and the techs who worked on it moved all my old info onto the new one. Well afterwards, I couldn't boot off of OS X, so I reinstalled it. I then noticed I had lost mySQL and PHP, and my Apache was corrupted. Soooo... I reinstalled them, but I had no config file or directory for individual users. My overall config file was different than the first time I compiled and installed it. I eventually fixed it all back, but I STILL have the CGI problem. And my Sharing will not work anymore. It'll crash the System Prefs every time. All other panels work, but not Sharing. I have to start Apache with the apachectl command. Anybody know how to help me with any of these things?

[ Reply to This | # ]
CGI's from the user's Sites folder
Authored by: ericrkl on Jul 19, '01 02:56:14AM

I found this on the MacFixit Forums from CapVideo:

"Add the following to the bottom of your .conf file:

<Directory "/Users/capvideo/Sites/cgi-bin/">
Options ExecCGI
AddHandler cgi-script .cgi
</Directory>

(replacing "capvideo" with your own Unix-level username) "

I experimented a little and changed ".cgi" to "cgi", as in the example from the Apache manual in OS X (under AddHandler).

Also, in my case, I made the "cgi-script" directory "rwxrwxr-x".

I tested an old "send form" perl script and all went well.

Path to original posting:
http://www.macfixitforums.com/php/showthreaded.php?Cat=&Board=Forum38&Number=175809&Search=true&Forum=Forum38&Words=apache&Match=Or&Searchpage=0&Limit=25&Old=allposts&Main=175809

Saludox,
eric



[ Reply to This | # ]
CGI's from the user's Sites folder
Authored by: jasont on Aug 02, '01 04:48:37AM

With the latest 1.0.4 and web update all you do is edit the scriptalias area of your apache configuration file and add this
ScriptAliasMatch ^/~([^/]*)/cgi-bin/(.*) /Users/$1/cgi-bin/$2

Then just place a cgi-bin directory in each users home area.
Still trying to figure out how to make the system autocreate one when I make a new user. Anyone?
-j



[ Reply to This | # ]
This works...
Authored by: Gee4orce on Sep 03, '01 11:53:53AM

Here's what I did (for username andy):

<pre>

<Directory "/Users/andy/Sites/">
Options Indexes MultiViews
AllowOverride all
Order allow,deny
Allow from all

</Directory>

AddHandler cgi-script .cgi .pl
<DirectoryMatch "^/Users/andy/Sites/?.*/cgi-bin/">
Options +ExecCGI -Indexes
SetHandler cgi-script
</DirectoryMatch>

</pre>

This turns on CGI executables (files with .cgi or .pl extensions) only in directories called 'cgi-bin' that live under andy's Sites folder (or subfolders thereof). It also turns of directory indexing (ie. listings) for these directories - good practice for hiding your cgi scripts from prying eyes.



[ Reply to This | # ]
This works...
Authored by: Vocal Velocity on Oct 15, '02 12:55:31PM

Upon following your example in changing the users.conf file and running apachectl configtest I received this syntax error:
Syntax error on line 11 of /private/etc/httpd/users/users.conf:
<DirectoryMatch not allowed here

My question is, where is the proper place to put the <DirectoryMatch?
also it did not like the <pre>



[ Reply to This | # ]