简体   繁体   English

在Ubuntu LAMP Server上设置Apache以在虚拟主机中执行Python

[英]Setting up Apache on Ubuntu LAMP Server to execute Python in Virtual Host

I am trying to setup a LAMP server in my lab, and I'm having trouble getting Apache to execute the .py files. 我正在尝试在实验室中设置LAMP服务器,但无法让Apache执行.py文件。 It instead just downloads them. 相反,它只是下载它们。 At first I thought my header might be wrong , but when I changed it, it unfortunately I'm still not executing the .py. 起初我以为标头可能是错误的 ,但是当我更改标头时,不幸的是我仍然没有执行.py。 On the plus side I can load the site, run the PHP, and CRUD the MySQL. 从好的方面来说,我可以加载该网站,运行PHP,然后对MySQL进行CRUD。 I think the problem might be in how I'm setting up my Virtual Host. 我认为问题可能出在我如何设置虚拟主机上。 Here is the Apache2.conf: 这是Apache2.conf:

<VirtualHost *:80>
    Alias "/SiteIwant" "/var/www/SiteIwant"
    ServerName localhost
    DocumentRoot /var/www/SiteIwant
    CustomLog /var/www/SiteIwant/my_access.log combined
    ErrorLog /var/www/SiteIwant/my_error.log
        AddType application/x-httpd-php .php
        SetEnv LD_LIBRARY_PATH /etc/init.d/mysql
    <Directory /var/www/SiteIwant>
        Options None ExecCGI
        AddHandler cgi-script .cgi .pl .py
        #AddHandler mod_python .py
        DirectoryIndex index.php
        AllowOverride AuthConfig
        Order deny,allow
        Deny from All
            Allow from 999.999.999.0/24 #anonymized for posting here, but working
    </Directory>
#   <Directory /var/www/SiteIwant/cgi/>
    #   AllowOverride All
    #   Options +ExecCGI +SymLinksIfOwnerMatch
    #   Order allow,deny
    #   Allow from all
    #</Directory>
</VirtualHost>

I've tried it with and without the specification on the cgi folder, and I've chkmod +rwx *.py in /var/www/SiteIwant/cgi . 我已经尝试过在cgi文件夹中使用和不使用规范,并且在/var/www/SiteIwant/cgi chkmod +rwx *.py Just for kicks (after that didn't help), I also changed the mode of the python interpreter in /usr/bin and /usr/local/bin to +rwx. 只是为了踢球(此后无济于事),我还将/ usr / bin和/ usr / local / bin中的python解释器的模式更改为+ rwx。

Everything else in the apache2.conf file is as it comes out from current Ubuntu Server-LAMP option install. apache2.conf文件中的其他所有内容均来自当前的Ubuntu Server-LAMP选项安装。

I feel very stuck and like I'm missing something stupid/small. 我感到非常卡住,就像我缺少一些愚蠢/小东西。

Edit: Should this really be asked on Server Fault? 编辑:这真的应该在服务器故障上被要求吗?

If I put an AddHandler cgi-script .cgi .pl .py outside the the Virtual Host, I get a 403 permission error, despite chmod 777 the folder. 如果将AddHandler cgi-script .cgi .pl .py放置在虚拟主机之外,则尽管文件夹chmod 777,我AddHandler cgi-script .cgi .pl .py收到403权限错误。

late answer, I got through there too and got this working by adding ExecCGI in directory option, or for more security, like this: 较晚的答案,我也到了那里,并通过在目录选项中添加ExecCGI来使此工作正常进行,或者为了提高安全性,例如:

<Directory /path/to/www/yourfile.py>
Options +ExecCGI
</Directory>

您是否已安装并启用了Apache wsgi模块?

This statement in the vhost and/or global config should be enough (and you have it in your config): 在vhost和/或全局配置中的以下语句应该足够了(并且在配置中已经包含了它):

AddHandler cgi-script .py

Did you reload Apache after changing the config? 更改配置后是否重新加载了Apache? If this doesn't work, you should check your webserver's errorlog, it should give some hints on the cause of the problem. 如果这不起作用,则应检查Web服务器的错误日志,它应提供有关问题原因的一些提示。

Also, you didn't describe what happens when you visit the URL hosting the python script, do you get an error message? 另外,您没有描述访问托管python脚本的URL时会发生什么,是否收到错误消息?

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

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