Chopp
Chopp

Reputation: 69

Testing CGI code on MacOS Sierra

I have some CGI code written in C that I've developed on an Ubuntu linux machine. It works fine, but I wanted to make some changes and update it while away on travel. Thought I'd set it up to test on my Mac laptop (macOS 10.12.1) using Xcode and Safari. Tried looking online for instructions on how to get apache to recognize the CGI code and found a few sites, but it still doesn't work.

Here's what I have so far:

  1. I set up a directory /User/username/Sites to store the html pages that will call the CGI code through a form. (where "username" is my username)

  2. I put the compiled CGI code in /Library/WebServer/CGI-Executables (Note: I also put them in /Users/username/Sites just in case)

  3. Following the online instructions, in /etc/apache2/httpd.conf I uncommented the following lines:

    LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
    LoadModule userdir_module libexec/apache2/mod_userdir.so
    AddHandler cgi-script .cgi
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    Include /private/etc/apache2/extra/httpd-userdir.conf
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  4. Also following the online instructions, I created the following file in /etc/apache2/users called username.conf (again, "username" is my username).

    <Directory "/Users/username/Sites/">
        AllowOverride All
        Options Indexes MultiViews FollowSymLinks
        Require all granted
    </Directory>
    
  5. When done with the above changes I restarted the apache server (also tried a full restart of the computer, but it didn't help).

I'm able to load the form page using http://localhost/~username/foo.html, but when I submit the form using the POST method to a code foo.cgi it just spits foo.cgi back at me and then safari dumps it in the download folder. Also tried writing a simple perl script and a simple cgi C code to just make a "hello world" web page and called it with http://localhost/~username/hello.pl (or .cgi). This gave me the same results, though for the perl script it spit the script itself back since it's just plain text.

There must be a step I'm missing, but haven't been able to find it. Any help would be greatly appreciated. Thanks!

DC

Upvotes: 1

Views: 1416

Answers (2)

Carlos Gortaris
Carlos Gortaris

Reputation: 1

Besides all you did, I also added ExecCGI Includes to the Options line at the /etc/apache2/users/username.conf file. Restarted and worked. Config file looks like this:

<Directory "/Users/username/Sites/">
    AllowOverride All
    Options Indexes MultiViews FollowSymLinks ExecCGI Includes
    Require all granted
</Directory>

Upvotes: 0

Chopp
Chopp

Reputation: 69

One step left out of the instructions I found online: need to also uncomment the line: LoadModule cgi_module libexec/apache2/mod_cgi.so in the httpd.conf file. Works now by putting the executables in the /Library/WebServer/CGI-Executables folder.

Upvotes: 1

Related Questions