Python – Running Python scripts on Apache Server: 403 Forbidden Error

amazon ec2apache-2.4http-status-code-403pythonubuntu-14.04

I need to run a few python scripts on a subdomain of my website set up using Apache on an AWS EC2 instance running Ubuntu. I tried following some of the steps mentioned in this post. I get a 403 error ("Forbidden. You don't have permission to access /index.py on this server.") while trying to access the subdomain.

I have a 755(-rwxr-xr-x) permission on the index.py file.

The subdomain.website.com.conf file:

<VirtualHost *:80>
    ServerAdmin webmaster@website.com
    ServerName subdomain.website.com
    DocumentRoot /var/www/html/subdomain.website.com/public_html
    Options +ExecCGI
    DirectoryIndex index.py
    AddHandler cgi-script .py
</VirtualHost>

Best Answer

My bad!

The directives Options and DirectoryIndex needed to be inside Directory tags.

The correct subdomain.website.com.conf file:

<VirtualHost *:80>
        ServerAdmin webmaster@website.com
        ServerName subdomain.website.com
        DocumentRoot /var/www/html/subdomain.website.com/public_html
        <Directory /var/www/html/subdomain.website.com/public_html>
                Options +ExecCGI
                DirectoryIndex index.py
        </Directory>
        AddHandler cgi-script .py
</VirtualHost>