48215

how to make apache run pyc file (python compiled file)

I am using apache2 and python2.6 on linux.

I know how to make apache run a *.py file, just add "AddHandler cgi-script .cgi .py" to httpd.conf file. But how to make apache2 run a *.pyc file?

Adding "AddHandler cgi-script .cgi .pyc" is not working.

I've heard that mod_python can enable both *.pyc and *.pyo run on apache. Could anybody tell me how does mod_python make it?

By the way in the current I don't want to learn mod_python or WSGI...

Thank you all in advance!

Answer1:

The problem is that httpd doesn't know how to run a .pyc file, since unlike a .py file (with its shebang line), a .pyc file contains no information on how it should be run. You will need to use binfmt_misc to instruct Linux on how to run a .pyc file. And don't forget to make the file itself executable as well.

Answer2:

It should work. If it doesn't, try running the .pyc file in question from the command line. If that does not work either, this superuser question might help.

Apart from that, I'm wondering what the reason is for not using the python source files?

Answer3:

In apache config file you add lines in section virtualhost:

ScriptAlias /cgi-bin/ /usr/bin/ Action cgi-handler /cgi-bin/python3 AddHandler cgi-handler .py .pyc .pyo <Directory /usr/bin> Require all granted Options FollowSymLinks </Directory>

This complete example of configuration file to www.domain.com.br.conf (in /etc/apache2/sites-enabled/)

DocumentRoot /home/domain.com.br/www/ ServerName domain.com.br ServerAlias www.domain.com.br <Directory /home/domain.com.br/www/> Options FollowSymLinks MultiViews Includes AllowOverride None Order allow,deny allow from all Require all granted </Directory> ScriptAlias /cgi-bin/ /usr/bin/ Action cgi-handler /cgi-bin/python3 AddHandler cgi-handler .py .pyc .pyo <Directory /usr/bin> Require all granted Options FollowSymLinks </Directory>

Recommend

  • Is it possible to replace Loader of an OS? Any way to obtain the control over Loader?
  • How to associate Python scripts with active virtualenv?
  • How to compile python code that uses boto to access S3?
  • there are errors to replace Linux kernel function
  • How does the shebang execute the program?
  • make a PHP script executable from CLI and include-able?
  • “Invalid multibyte char (US-ASCII)” error for ä, ü, ö, ß which are Ascii!
  • Remove doc strings but not asserts from compiled CPython
  • Pure black background in PyCharm CE and Android Studio
  • Java Date and Time Formatting
  • How to discover what is available in lua environment?
  • Alternative for django.db.close_connection()
  • Using custom dll in Qt Application
  • How to write Delphi ActiveX control which can be used in MS Word/Excel/Powerpoint?
  • Sorting parallel arrays in javascript
  • How to specify columns in Swagger
  • What's a better way to swap two argument values?
  • How to use a decaying learning rate with an estimator in tensorflow?
  • Google App Engine - SSL InsecurePlatformWarning
  • Connect Node.js with Oracle on Windows platform
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Using $this when not in object context
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Join two tables and save into third-sql
  • Perl system calls when running as another user using sudo
  • How to model a transition system with SPIN
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • ORA-29908: missing primary invocation for ancillary operator
  • Web-crawler for facebook in python
  • R: gsub and capture
  • PHP: When would you need the self:: keyword?
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • reshape alternating columns in less time and using less memory
  • Converting MP3 duration time
  • Net Present Value in Excel for Grouped Recurring CF
  • How can I use threading to 'tick' a timer to be accessed by other threads?