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!
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.
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?
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>