Deploy Flask on Godaddy Linux share hosting with cPanel

阅读更多
1 test your python environment, be attention that put your python code on document root fold or sub folder cgi-bin, otherwise your code is not able to accessed through cgi.

here is sample of testing python code:

#!/usr/bin/python
#hello.py
print "Content-Type: text/html"     # HTML is following
print
print "
Test CGI Python
Hello CGI!"

set privilege to 755 !!!!!!!(dont know why)
Meanwhile add a handler for extension .py through cPanel or change hello.py to hello.cgi

run it through : http://yourdomain.com/hello.py or hello.cgi

2 install virtualenv pip and create your own python environment and install Flask through pip.

3 create cgi application under folder of cgi-bin:
#!/yourpythonpath/python
#myapp.py
from wsgiref.handlers import CGIHandler
from yourapplication import app

CGIHandler().run(app)


4 create myapp folder under document root, create .htaccess inside of myapp:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/yourloginname/public_html/cgi-bin/myapp.py/$1 [L]


Be careful that although there is a link www point to public_html folder, but it does not work if you put here www.

test link: http://yourdomain.com/myapp/



reference: http://flask.pocoo.org/docs/deploying/cgi/

Regarding FastCGI on Godaddy shared host:

I have successfully config Flash with FastCGI through flup, but it does not make sense. Since the socket will be closed after a HTTP access, apache creates a new process to deal with a new request.

Lets look into flup source code:
            sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET,
                                 socket.SOCK_STREAM)
            try:
                sock.getpeername()
            except socket.error, e:
                if e[0] == errno.ENOTSOCK:
                    # Not a socket, assume CGI context.
                    isFCGI = False
                elif e[0] != errno.ENOTCONN:
                    raise

sock.getpeername() will throw a exception, which indicate that socket does not exist, there is no different between CGI and FastCGI on initialising of python app.

I also got proof on Godaddy support website:
https://support.godaddy.com/help/article/20/does-your-cgi-service-support-socket-connections-or-socket-modules

你可能感兴趣的:(python,Flask,godaddy,CGI,FastCGI)