Executing a Python script in Apache2

前端 未结 6 1836
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 22:51

I am trying to execute a Python program using Apache. However, Apache will only serve the file and not actually execute it. The permissions on the file are r/w/x and it is

6条回答
  •  执笔经年
    2020-12-04 23:23

    **For apache2 version 2.4

    sudo apt-get install python
    sudo apt-get install apache2
    

    edit file /etc/apache2/conf-enables/serve-cgi-bin.conf

    ====comment old section and add code below:

    ScriptAlias /cgi-bin/ /var/www/cgi-bin/
    
    AddHandler cgi-script .py
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    
    

    =========================================

    edit file /etc/apache2/apache2.conf ***add code below:

    
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
    
    
    
    Options All
    
    
    
    Require all granted
    
    

    Note!

    use for apache2.4 
      file python keep in directory: /var/www/cgi-bin/
      You can test :go to http://localhost/cgi-bin/.py
    

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

提交回复
热议问题