9

Okay, I am a beginner with all this, so don't expect me know much. Let me know if this is the wrong place to ask this. What tags should I have used? THANKS a lot for your time.

Background

I have a CGI script saved in /Library/WebServer/CGI-Executables.

I used to be able to run the script using the URL: http://localhost/cgi-bin/filename,

Problem

But now, Safari can't connect to the server?! Once or twice it begins to load then stays for a long time and eventually the same error comes up.

What could the problem be?

Extra Q's

I found my apache2 folder in /private/log/apache2 should this be moved?

Can I somehow run this script on something else without a server? Terminal works, but it is too hard to read.

9
  • is localhost up, is a server running ? That should be the first step.
    – phwd
    Commented Jun 17, 2011 at 18:06
  • Okay, sorry, but how to I check that?
    – Jon
    Commented Jun 17, 2011 at 18:11
  • @Jon The same way you checked for the script, type it into Safari http://localhost/
    – phwd
    Commented Jun 17, 2011 at 18:24
  • Oh, ya, I've tried that before. NO same error.
    – Jon
    Commented Jun 17, 2011 at 18:32
  • Do this in a terminal: "ps -eaf | grep httpd"; if you get anything more than the "grep" line, things are running (but may need restarted). Otherwise Apache isn't running at all. (I've had occasions on other platforms where Apache will be running with httpd processes, but not respond to requests, so it is worth a check to see if there are processes running.) Commented Jun 17, 2011 at 18:49

3 Answers 3

6

It seems like you are using Mac's built-in server and maybe somewhere along the line, web sharing was disabled.

Go to your System Preferences and enable Web Sharing.

To be sure httpd has started do what @Kerri mentioned in the comments

ps -eaf | grep httpd

which will display all processes that contain httpd as well as the Process ID

if you only get something like the following

501 22299 22030   0   0:00.00 ttys001    0:00.00 grep httpd

grep is the only process running referencing httpd

At this point try stopping and restarting the server manually

sudo httpd -k stop  
sudo httpd -k restart

Look also into the Console.app log and filter to see what information you can get from there.

If it is enabled you should get the following on pointing to localhost within a browser

It works!

So far so good, the server is running.

Now to navigate to the cgi-bin folder, if you used the scripts before then it should be mapped already in your configuration.

You could get

Forbidden

You don't have permission to access /cgi-bin/ on this server.

or an Internal Server Error if you went straight to the script

and you can chmod 755 the script and that should give you the correct permission to run it.

You can also check the access and error logs to see what's up

/var/log/apache2/access_log
/var/log/apache2/error_log

/var is the symbolic link to private/var

4
  • Unfortunately, I've restarted the Web Sharing many times but it still doesn't work. I've run them before (after changing the permissions) but still nothing... Thanks though. Seems like the problem is deeper than I thought
    – Jon
    Commented Jun 17, 2011 at 18:57
  • @Jon what does it say in your logs? Check /var/log/apache2/error_log after you try and view the web page.
    – ghoppe
    Commented Jun 18, 2011 at 0:28
  • @ghoppe see apple.stackexchange.com/questions/16116/…
    – phwd
    Commented Jun 18, 2011 at 0:40
  • This might be helpful to somebody as well if you are seeing "apr_sockaddr_info_get() failed" - linux.101hacks.com/unix/httpd-apr-sockaddr-info-get-error Commented Feb 14, 2021 at 12:06
0

Run the following to see any other non-obvious errors. I did all the above and have had this Mac (without rebuilding -just upgrading and upgrading etc.) pre2004 - just kept upgrading - so there was quite a history on this mac. There were some skeletons in the closet. I JUST upgraded to Mountain Lion when the lid came off my web server.

Run this - look for errors on the output line.

sudo httpd -E /private/var/log/apache2

I had a module installed (SVN – but that is merely a detail) and it was loaded in the other category at the end of the httpd.conf file.

Here is the output of the command line – it pointed to the issue:

httpd: Syntax error on line 500 of /private/etc/apache2/httpd.conf: Syntax error on line 1 of /private/etc/apache2/other/svn.conf: Cannot load /usr/libexec/apache2/mod_dav_svn.so into server: dlopen(/usr/libexec/apache2/mod_dav_svn.so, 10): image not found

I renamed the svn.conf file to svn.deletedconffile and apache started right up. I also had to chmod to 755 all my Sites files – not 644 which is suggested on some sites.

-2

if you created a username.conf file in mountain lion delete it. After doing so restart apache and all should be well :)

1
  • 2
    How should this help in accessing localhost? The user.conf files are only needed to access localhost/~user
    – nohillside
    Commented Dec 30, 2012 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .