How to run python script in localhost using XAMPP on MAC OS

I am trying to run a simple Python script using XAMPP on my MAC. I followed this link. In any case, I will tell you what I did in stages.

I am running MAC OS X 10.9.5 and I have python 2.7.5 and python 3.4.1 installed on this machine. Also I have successfully installed XAMPP 1.8.3-5 on this computer and tested it on PHP and HTML pages.

The next thing I did was create a directory called cgi-bin in the path / Volumes / Macintosh \ HD / Applications / XAMPP / xamppfiles / htdocs / . Inside this directory, I created a file name first.py with the content below.

#!/usr/bin/env python
print "Content-type: text/html\n"

print "Hello, world!"

      

Just for testing purposes, I ran this file in Terminal to make sure I have the right fingerprints.

$ python /Volumes/Macintosh\ HD/Applications/XAMPP/xamppfiles/htdocs/cgi-bin/hello.py

      

Yes, it works well. Then I changed the resolution of the file as well as the resolution function.

drwxrwxrwx   5 anuja   mygroup     170 Nov 14 17:40 cgi-bin/

      

and

-rwxr-x--x@  1 anuja  mygroup   82 Nov 14 16:05 first.py*

      

The next step was to configure the httpd.conf file . I download the XAMPP control panel, then select the Service Management tab and select Apache Web Server and click the Configure button. From the popup, I clicked Open Conf File.

Here I will comment out the following line

# ScriptAlias /cgi-bin/ "/Applications/XAMPP/xamppfiles/cgi-bin/"

      

Then add the following block

<Directory "/Volumes/Macintosh\ HD/Applications/XAMPP/htdocs/cgi-bin/">
    AddHandler cgi-script .cgi .py
    AllowOverride All
    Options +Indexes FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all
</Directory>

      

There is a similar block of directories in there and I kept it as it is above the given block.

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

      

After restarting the Apache server from the XAMPP panel, I tried to load it using my web browser

http://localhost/cgi-bin/first.py

      

Finally, I ended up with an "Object not found" error in the browser. I tried several changes but no luck. How can I run this python script from a web browser, I am getting Hello world! how out put?

0


source to share





All Articles