Question

I'd like to do the CGI programming with Apache and Perl in Max OS X 10.8.5. I followed the guide : CGI Programming With Apache and Perl on Mac OS X. The steps are:

  1. edit /etc/apache2/httpd.conf, uncomment the following:

    AddHandler cgi-script .cgi  .pl

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
  1. edit /etc/apache2/userName.conf:


Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI
DirectoryIndex index.html index.cgi
AllowOverride None
Order allow,deny
Allow from all

  1. start apache:

sudo apachectl restart
  1. put a cgi file into the folder: ~/Sites. I have update the privilege of test.cgi:

sudo chmod 755 test.cgi

That's all I have done. However, when I visit : ht tp://localhost/~userName/test.cgi, the result:

Forbidden

You don't have permission to access /~username/test.cgi on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I try to put a html into the ~/Sites, and it can be shown correctly. It seems there is something wrong with the cgi configurations, but I can't find it. Could anyone give some guides?

thanks!

Was it helpful?

Solution 3

The steps in CGI Programming With Apache and Perl on Mac OS X are correct. If restarting apache does not work, restart the mac! And Now I can use the cgi!

OTHER TIPS

The following steps worked for me on High Sierra running Apache 2.4

( Based on the following excellent tutorial: http://www.cgi101.com/book/connect/mac.html , updated with additional steps for version differences)

1) Move the file to:

/Library/WebServer/CGI-Executables

2) Verify that the file has execution permissions:

ls -l  /Library/WebServer/CGI-Executables

If not use:

chmod -x  /Library/WebServer/CGI-Executables/myfile.cgi

3) Uncomment the following lines in /etc/apache2/httpd.conf

AddHandler cgi-script .cgi .pl

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

LoadModule cgi_module libexec/apache2/mod_cgi.so

4) Also change the Directory "/Library/WebServer/CGI-Executables" stanza to:

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

5) Then restart Apache:

 sudo apachectl -k restart

Almost with every new Mac OS version, the changes will become lost and you will need to redo the work, and even do different steps to fix it. Your best friend are the Apache logs located in /var/log/apache2/ (/var/log/apache2/error_log)

The OSX Apache serves "two" servers. One public directly for the localhost and one for each user. Check out the configuration of your user directories in /etc/apache2. There is a users directory having each OSX user on that machine a own configuration like that:

<Directory "/Users/markus/Sites/">
    Options Indexes MultiViews FollowSymLinks Includes ExecCGI
    AllowOverride All
    Allow from all
</Directory>

<VirtualHost *:80>
    ServerName sencha
    DocumentRoot "/Users/markus/Sites/sencha"
</VirtualHost>

Also make sure, the userprofiles are enabled in the httpd.conf

# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top