2014/03/02

Ubuntu 12.04 LTS Apache2加入Python

將程式碼新增至/var/www/index.py
#!/usr/bin/python3
import cgi

cgi.test()





將下方文字新增至/etc/apache2/httpd.conf
<Directory /var/www/index.py >
  Options +ExecCGI
  AddHandler cgi-script .py
  Order allow,deny
  Allow from all
</Directory>





將Apache重新啟動
sudo /etc/init.d/apache2 restart


輸入IP/index.py即可看到Python透過cgi來執行




參考資料:
http://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2