Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

CGI on Mac OS 10.11

by Chuma (Scribe)
on Feb 03, 2016 at 02:36 UTC ( [id://1154312]=perlquestion: print w/replies, xml ) Need Help??

Chuma has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I'm trying to get a CGI script running on my newest mac. In short, I'm following the instructions on http://editrocket.com/articles/perl_apache_mac.html
This is for an older OS version, so the last instruction on how to start/restart the server doesn't work, and I have to use the terminal instead; sudo apachectl start etc.

But it still doesn't work - the file still shows up in the browser as plain text. I know it's possible to change the configuration so that CGI files can be run anywhere (as explained, for example, in http://www.alecjacobson.com/weblog/?p=1749). But since it's in the CGI-Executables folder, it's supposed to work already, right? What else am I missing?

Replies are listed 'Best First'.
Re: CGI on Mac OS X 10.11
by kcott (Archbishop) on Feb 03, 2016 at 09:27 UTC

    G'day Chuma,

    I'm runnng Mac OS X 10.10.3 (Yosemite). Your version, Mac OS X 10.11.x (El Capitan), has quite a few restrictions which are new: just be aware that information I've provided below may not be valid for your version. I don't believe these restrictions are related to your current issue (although I make no guarantees); however, as this is your "newest mac", it would be a good idea to acquaint yourself with them. The overall change is called "System Integrity Protection" (SIP). Here's a good article about SIP, with links to further information.

    Simply running `sudo apachectl start` may not be sufficient. You may need to stop first; then start. I have the following sourced by .bash_profile:

    alias bounce_apache='sudo apachectl stop 2> /dev/null; sudo apachectl +start'

    I set this up some years ago (under Mac OS X 10.7.x, I think) and it's always worked well for me. Take a look at /usr/sbin/apachectl for other options.

    I followed the instructions in http://editrocket.com/articles/perl_apache_mac.html and got the same results as you, i.e. just a program listing.

    I then made the following changes to /etc/apache2/httpd.conf:

    • Uncommented:

      #LoadModule cgi_module libexec/apache2/mod_cgi.so
    • Changed the Options line in:

      <Directory "/Library/WebServer/CGI-Executables"> AllowOverride None Options None Require all granted </Directory>

      to

      Options +ExecCGI

    After running bounce_apache, http://localhost/cgi-bin/test.pl displays: Test Page

    You may require slightly different changes depending on your setup but, I think, that should get you on track.

    [Aside: Please markup URLs as links (see "Shortcuts for Markup Links" if you're unfamiliar with how to do this). Also note, my title has "Mac OS X" while yours has "Mac OS" which, I believe, is rather ancient (in computer terms).]

    — Ken

      Hm, looks like my other comment ended up anonymous. Anyway, as I said, I changed the conf file, stopped and started Apache, and it didn't work at all; the browser said it couldn't find the server. As for SIP, I heard about it a few days ago. Didn't like it, switched it off.

        Do you have an access.log and error.log in possibly /var/log/apache2/ ?

        As poj has hinted, your config changes to apache config files may have an error, preventing apache from starting. The error.log should show what the problem is.

        The apache config should contain something like this:

        <Directory "/Library/WebServer/CGI-Executables"> AllowOverride None Options +ExecCGI Require all granted </Directory>

                ...The words of the Prophets are written on the Facebook wall.

Re: CGI on Mac OS 10.11
by NetWallah (Canon) on Feb 03, 2016 at 03:02 UTC
    You need to give us a little more info, to be able to help.
    Show us the response to:
    ls -l /Library/WebServer/CGI-Executables/
    and
    sudo apache2ctl restart
    Also - did you paste in EXACTLY the code recommended at http://editrocket.com/articles/perl_apache_mac.html ?

    Can you also show the output of:

    perl /Library/WebServer/CGI-Executables/test.pl
    Apache also keeps a log of requests made .. you should be able to locate
    /var/log/apache/access.log and error.log.

    Check the content of those files. (The location may be slightly different on a mac).

    Apache configuration files located under /etc need to point to the CGI directory.

            "I can cast out either one of your demons, but not both of them." -- the XORcist

      Yep, copied the code straight from the webpage. Tried stopping and starting Apache several times. Here's some terminal output.

      Megan:~ Chuma$ ls -l /Library/WebServer/CGI-Executables/ total 8 -rw-r--r-- 1 root wheel 1074 Dec 17 2012 printenv.vbs -rw-r--r-- 1 root wheel 1133 Dec 17 2012 printenv.wsf -rwxr-xr-x@ 1 Chuma staff 157 Feb 3 02:52 test.pl
      Megan:~ Chuma$ perl /Library/WebServer/CGI-Executables/test.pl Content-type: text/html; charset=iso-8859-1 <html><body>Test Page</body></html>Megan:~ Chuma$

      kcott: I tried those changes, but now it doesn't work at all - browser says it can't find "localhost".

Re: CGI on Mac OS 10.11
by Cody Fendant (Hermit) on Feb 04, 2016 at 05:55 UTC

    Slightly off-topic, but I would advise you to use XAMPP rather than the current OS X's web server setup.

    Even if you get this first script working, you're probably going to be back in five minutes trying to get DBI and MySQL set up, or includes or twenty other things.

    The whole point of XAMPP is to get past all those hassles and get working with the technology.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1154312]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-24 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found