Home > Back-end >  python files not executing on server
python files not executing on server

Time:12-31

I have installed python3.6 on root, created python_app folder inside public_html directory running this .py file

#! /usr/bin/python

print "Content-type: text/html\n\n"
print "Hello world!!"

but it is rendered as plain text in browser,

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Force SSL
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Any solution

CodePudding user response:

You need to configure Apache to run your Python scripts as CGI.

Create an .htaccess:

Options  ExecCGI
AddHandler cgi-script .py

CodePudding user response:

While the suggestion to use ExecCGI is good, I find it's better to use a WSGI implementation such as uWSGI or gunicorn instead.

  • Related