xampp には標準で python が入っているけど残念ながら python が入ってないので使いたかったら自分で入れる必要があるらしい。なので入れてみた。
環境
Windows 7 32bit
Xampp 1.7.7
Python 2.6.1 (Portable)
必要なもの
Xampp python
で検索すると python の情報が出てきてインストール方法も色々と出てくるんだけれども python の windows 版は python のバージョンが 2.5 までにしか対応してないようで非常にめんどくさそう。
色々探してたら簡単な方法を載せてるサイトが見つかったのでその方法を紹介します。
インストールが必要な物は何もなし。ヽ(´▽ `)ノ
設定方法
まず
[xampp をインストールしたディレクトリ]\apache\conf\httpd.conf
を開いて
# # For Python # AddHandler cgi-script .py ScriptInterpreterSource Registry-Strict
と追記します。
場所は多分どこでもいいけど、既に
“AddHandler cgi-script .cgi .pl .asp"って書いてる所があるのでその下にでも。
んで、動かしたい python スクリプトの行頭に
#!P:\Dropbox\bin\Python26\App\python.exe
と python.exe がある場所を書いておきます。
以上で終わり。
確認
#![python.exeの置いてる場所]\python.exe print "Content-Type: text/plain" print print "hello world."
と書いて[xampp のフォルダ]\htdocs\pythontest.py に保存して
xampp_start.exe でサーバーを起動させて
http://localhost/pythontext.py
を開いて “hello world.“が表示されたら OK。
サーバーが起動してる状態で設定したら xampp を一回終了させて再起動させないと動きません。
やっとくと便利なこと
http://localhost/index.html が
http://localhost/ でも開けるように
http://localhost/index.py が
http://localhost/ でも開けるように設定しときましょう。
# # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml index.py </IfModule>
参考
Getting python to work on Xampp
http://www.macouno.com/2010/03/17/getting-python-to-work-on-xampp/