简体   繁体   中英

How to install python cgi on apache2?

I want to call a Python script using javascript. For this I need to install cgi on my apache server to call python script. (Maybe I wrong, I'm beginner and I'm little lost...) But I don't know how to do this...

I have this in my 000-default.conf :

<VirtualHost *:80>

  DocumentRoot /var/www/html

  php_value include_path ".:/var/www/html:/usr/share/php:/usr/share/pear"
  php_value post_max_size 30M
  php_value upload_max_filesize 30M

  <Directory /var/www/html/>
      Options All -Indexes
      AllowOverride All
      Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

So I don't have cgi, any idea to install this?

You can follow this link . But in short you have to add this

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
  Options +ExecCGI
  AddHandler cgi-script .py
  Options FollowSymLinks
  Require all granted
</Directory>

Now you can place all your python scripts in that cgi-bin directory and execute them as http://localhost/cgi-bin/myscript.py in your browser , boom.

Or a more simple but less production freindly way is installing XAMPP and put the scripts in /opt/cgi-bin/ directory already created and run the above mentioned url in your browser boom , done for now.

Are you trying to do AJAX? Thats you want to call cgi scripts using Javascripts to draw dynamic websites? If thats true I would strongly advise in not doing so, it would draw a huge amount of resources from your server but if your using only python with a framework like Django or Flask , you would have no problems but for deploying them with normal PHP sites is a lot of headache which is not even its worth.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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