apache is included in mac by default. Check the version.
$ httpd -v
Server version: Apache/2.4.9 (Unix)
Server built: Sep 9 2014 14:48:20
How to start and restart. The default is port 80, so [http: // localhost].
$ sudo apachectrl start
$ sudo apachectrl stop
Enable cgi_module. Since it is a comment, remove it and restart.
LoadModule cgi_module libexec/apache2/mod_cgi.so
Looking inside httpd.conf, the settings are as follows.
Create and change "~ / Web / doc" and "~ / Web / cgi".
DocumentRoot "/Users/myname/Web/doc"
<Directory "/Users/myname/Web/doc">
...
</Directory>
<IfModule alias_module>
ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Users/myname/Web/cgi/$1"
</IfModule>
#
<Directory "/Users/myname/Web/cgi">
...
</Directory>
All that is left is to check the operation. Create a python script like the one below with + x and access "localhost / cgi-bin / test.py".
test.py
#!/usr/bin/python
print 'Content-Type: text/html\n\n'
print "Hello world!"
Recommended Posts