How to configure Apache to run Python on Mac (iOS)

Step 1: configure httpd.conf


<Directory "/Applications/XAMPP/xamppfiles/cgi-bin">
    AllowOverride None
    Options None
    Require all granted


<Directory "/Applications/XAMPP/xamppfiles/cgi-bin"> 
    AddHandler cgi-script .cgi .py
    AllowOverride All
    Options +Indexes +FollowSymLinks +ExecCGI
    Order allow,deny 
    Allow from all 
    Require all granted 

If no “Require all granted”, it will show “Access Forbidden” when you visit your file on browser.

Step 2: put your python file e.g. in the folder cgi-bin

Example is as below:


print "Content-type: text/html\n"

print "Hello, world!"

use sudo chmod 755 to make it executable.

Step 3: then go to browser, type “http://localhost/cgi-bin/”, you will see “Hello World”.

Please don’t forget “Content-type: text/html\n”, otherwise it will show:

Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
malformed header from script ‘’: Bad header: Hello, world!

In addition, you may need to change the permission of cgi-bin and

The commands are: sudo chmod 775 cgi-bin

and: sudo chmod 755 cgi-bin/


Leave a Reply

Your email address will not be published. Required fields are marked *