Recently I’ve caught myself writing more code on my Macbook and for the first time in… YEARS, not needing an internet connection to actually be productive. To be quite honest, it’s a bit weird.
So, the first thing I wanted was the ability to run/exec CGI via a webserver. At first, I was thinking I’d go about a source build of Apache, and then I remembered OSX comes with one built in. Huzzah!
So, first let’s enable the builtin webserver.
System Preferences -> Sharing, and then click on “Web Sharing”. Go ahead and close out the window now, you’ve just fired off Apache. (hooray!). You should now be able to open your browser of choice and go to http://127.0.0.1/~ Now, the document root is going to be off of your user account in /sites/. My user is chrismm on my machine, so /Users/chrismm/Sites/ is my public HTML. Any web content you want to view with the above URL needs to go off of this directory. Go ahead and add the obligatory "Helloworld.html", I'll wait. Now that that's done and functioning, I needed to get some hawt hawt Perl/CGI action going on. This, was incredibly easy. OSX's main httpd.conf does a per-user http include in /private/etc/apache2/users/ First and foremost, we need to be the root user, so go ahead and open up Terminal (Finder->Applications->Utilities -> Terminal), and type ‘sudo su -’ . Here, you’ll be prompted to enter your password. Keep in mind as soon as you do this, you are the root user on your machine, ***BE VERY CAREFUL AS IF YOU ARE NOT YOU CAN END UP WITH A WORTHLESS WORKSTATION ***. Now, go ahead and open up the include for your user, at /private/etc/apache2/users/
Original:
maynard:beta root# cat /private/etc/apache2/users/chrismm.conf
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
Needs to be changed to....
maynard:beta root# cat /private/etc/apache2/users/chrismm.conf
Options Indexes MultiViews ExecCGI
AllowOverride None
Order allow,deny
Allow from all
See that? All I added was “ExecCGI” at the end of that Options statement. We’re halfway done now!
One more change…
Go ahead and open up ‘/private/etc/apache2/original/httpd.conf’ in your text editor of choice, and search for ” #AddHandler cgi-script .cgi”
Go ahead and remove the ‘#’ mark, save and exit.
Now, let’s restart the webserver…
killall -HUP httpd
Done!
And now, you can use your CGI and be happy.
Comments