Configure cgi on mac (without the apache cgi that comes with the system.)
install cgi
1. brew update 2. brew install httpd24
After installation, the following prompt will appear
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To have launchd start httpd now and restart at login:
brew services start httpd
Or, if you don't want/need a background service you can just run:
apachectl start
open apache
3. brew services start httpd
Type in the browser
The default port of apache installed by brew is 8080, and the default port of apache that comes with mac is 80
Modify the httpd.conf file
Add two lines: LoadModule cgi_module lib/httpd/modules/mod_cgi.so LoadModule cgid_module lib/httpd/modules/mod_cgid.so Modify the contents of the <Directory "/usr/local/var/www/cgi-bin"> tag as follows, ExecCGI means to execute cgi scripts in the cgi-bin directory, and all cgi scripts need to be placed in the modified directory. <Directory "/usr/local/var/www/cgi-bin"> Options ExecCGI AllowOverride None Order deny,allow Allow from all </Directory> Uncomment the following three lines: AddHandler cgi-script .cgi AddType text/html .shtml AddOutputFilter INCLUDES .shtml Add a supported cgi script format after AddHandler cgi-script .cgi, such as .sh .pl. Since I use shell script here, all modifications are AddHandler cgi-script .cgi .sh
edit permission
chmod +x /usr/local/var/www chmod +x /usr/local/var/www/cgi-bin
restart the server
brew services restart httpd
Put the test script delete.sh under /usr/local/var/www/cgi-bin
#!/bin/bash echo "Content-type: text/html" echo "" # ok, we've sent the header, now send some content rm -f $QUERY_STRING if [ "$?" -eq 0 ]; then echo "Deleted!" else echo "Delete failed!" be
Need to give delete.sh permission
chmod +x /usr/local/var/www/cgi-bin/delete.sh
open in browser
localhost:8080/cgi-bin/delete.sh?1.png
or with curl
curl "localhost:8080/cgi-bin/delete.sh?1.png"