简体   繁体   English

如何在 ubuntu 中使用 xampp 运行 python 脚本

[英]How to run python script with xampp in ubuntu

I'm using xampp installed on Ubuntu.我正在使用安装在 Ubuntu 上的 xampp。

What I did: [edited the following line in httpd.conf] AddHandler cgi-script.cgi.pl.asp.py我做了什么:[编辑 httpd.conf 中的以下行] AddHandler cgi-script.cgi.pl.asp.py

My python script present in htdocs is:我在 htdocs 中的 python 脚本是:

#!/usr/bin/python3

import cgitb

print("Content-Type: text/html;charset=utf-8\n")
print ("Hello Python Web Browser!! This is cool!!")

Output result is: End of script output before headers: sample.py Output 结果是:脚本结束 output 在标题之前:sample.py

Looking at error log from comments, the file does not have correct permissions to execute.从评论中查看错误日志,该文件没有正确的执行权限。 Simply do简单地做

$ sudo chmod -R 777 /opt/lampp/htdocs/portScanner

WARNING: It is really a bad idea to change permissions to 777 on a webserver, alternatively you could try changing ownership of this directory to the apache user which is usually www-data in ubuntu警告:在网络服务器上将权限更改为777确实是个坏主意,或者您可以尝试将此目录的所有权更改为 apache 用户,该用户通常是 ubuntu 中的www-data

$ sudo chwon -R www-data /opt/lampp/htdocs/portScanner

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM