Thursday, February 23, 2017

Run Python as CGI in Apache2

1. Install apache2
sudo apt-get install apache2 

2. Install python
sudo apt-get install python 

3. Enable CGI processing in apache2
sudo a2enmod cgi

4. Modify file /etc/apache2/sites-available/000-default.conf to include:
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /var/www/cgi-bin/
        <Directory "/var/www/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                AddHandler cgi-script .py
                AddHandler default-handler .html .htm
                Allow from all
        </Directory>
        <Directory "/var/www/run">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                AddHandler cgi-script .py
                AddHandler default-handler .html .htm
                Allow from all
        </Directory>
        <Directory "/var/www/tracedecode">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                AddHandler cgi-script .py
                AddHandler default-handler .html .htm
                Allow from all
        </Directory>

        # AddHandler mod_python .py

5. Restart apache2
sudo service apache2 restart



https://www.linux.com/blog/configuring-apache2-run-python-scripts

No comments:

Post a Comment

Followers

About Me