1

I am trying to setup a LAMP server in my lab, and I'm having trouble getting Apache to execute the .py files. 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. On the plus side I can load the site, run the PHP, and CRUD the MySQL. I think the problem might be in how I'm setting up my Virtual Host. Here is the 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. 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.

Everything else in the apache2.conf file is as it comes out from current Ubuntu Server-LAMP option install.

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.

3 Answers 3

1

late answer, I got through there too and got this working by adding ExecCGI in directory option, or for more security, like this:

<Directory /path/to/www/yourfile.py>
Options +ExecCGI
</Directory>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for digging this up. That worked like a charm. It's on a closed network, so I'm not too concerned about the security, but why would that be more secure?
In my example, i allowed only /path/to/www/yourfile.py to be executed as CGI so even if an harming file is put in the same directory, it will not be executed by the web server.
0

Do you have the apache wsgi module installed and enabled?

2 Comments

I don't know is the short answer, I'm trying to check now. I certainly didn't do it manually if it wasn't thrown in on the LAMP install.
I think you might be talking about the mod_wsgi in which case, no I don't think that it is. Should I install it? Just looking here: help.ubuntu.com/community/HelpOnInstalling/ApacheWithModWSGI I wouldn't think that it's needed?
0

This statement in the vhost and/or global config should be enough (and you have it in your config):

AddHandler cgi-script .py

Did you reload Apache after changing the config? If this doesn't work, you should check your webserver's errorlog, it should give some hints on the cause of the problem.

Also, you didn't describe what happens when you visit the URL hosting the python script, do you get an error message?

6 Comments

When you visit the python script, it just downloads the python and displays in plain text. No error seems to be generated (in the log as well). And it would seem I have the handler added in the vhost config.
A quick test tells me that this should be enough. Check permissions of the file (readable and executable by the uid the webserver is using) and if your statement is in the right vhost.
As far as reloading goes, I ran sudo apache2ctl restart, is that the same?
Yes, restart does even more than just reloading the config.
I feel like the permissions might be the problem. How would I check change them for the uid the webserver is using? I've done "sudo chmod +rwx *.py" in the folder where they are located. I haven't tried to do anything with: User ${APACHE_RUN_USER} or Group ${APACHE_RUN_GROUP}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.