Deployment of flash applications on 1 and 1 shared hosting (with CGI)

I wrote a web application for my sports club with a flash card. I did everything on my local machine using the built-in test server.

Know that they told me to deploy it on the same web space with shared access 1 and 1. They have python support, but it looks like they allow CGI to run python scripts.

I tried this tutorial: flask through CGI

I have ignored the rewriting material so far. All requests to my CGI script resulted in a 404 error. I changed my 404 handler in the application to return request.path . When I request /foo/runserver.cgi/, it returns / as output. I have no idea why it does not support the index. It does not work with any kind, I always get 404.

Regards, Sebastian

+6
python flask cgi
source share
3 answers

I have found a solution! I left /$1 aside from my .htaccess and changed werkzeug a bit because the environment variables in CGI are named slightly different in WSGI applications. I will let the werkzeug developer know this and maybe he will include my solution in werkzeug.

+4
source share

I am writing to give an answer after almost a year, because this answer is incomplete and because the proposal to leave / $ 1 is incorrect. Other stackoverflows that can be achieved by searching the web using the string "checkbox deployment flag on cgi" also ended without satisfactory solutions.

To begin with, my .htaccess file is exactly the same as in the reference document "flask via CGI", except that the comment in the second line for RewriteCond must be deleted, because in .htaccess any comment must occupy a whole line.

I put the .htaccess file in the root folder of the public_html document, and my cgi script is / home / myusername / public _html / scgi-bin / moc / cgiappserver-prod.cgi.

This is Python, of course, and the shebang at the top is better off being right. On my ISP, they use cpanel, which has a wrapper for CGI, which they call "scgi". This, unfortunately, is not the real thing . Therefore, consider it like regular CGI for the purpose of launching Flask.

I must add that I only have an account with shared hosting.

Here is my cgiappserver-prod.cgi file:

 #!/home/myusername/local/bin/python import cgitb; cgitb.enable() # This line enables CGI error reporting from wsgiref.handlers import CGIHandler import traceback from settings import LGGR app = None try: import moc app = moc.app except Exception, e: LGGR.info( traceback.format_exc([10]) ) LGGR.info( 'Problem in cgiappserver-prod with moc import: %s' % e ) class ScriptNameStripper(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ['SCRIPT_NAME'] = '' return self.app(environ, start_response) app = ScriptNameStripper(app) try: CGIHandler().run(app) except Exception, e: LGGR.info( traceback.format_exc([10]) ) LGGR.info( 'Problem in cgiappserver-prod with CGIHandler().run(): %s' % e ) 

So, my application is distributed across several files with the settings.py and moc.py parameters, in particular, in the above code.

My watch as we walked around was partly due to all the useless messages on this subject that I read, but mainly due to the fact that I did not receive messages about receiving error messages early enough. (I have access to the error log provided by the provider, but this is rarely useful.)

To get started, I confirmed that the cgitb.enable () function works. I deliberately sealed wsgiref and saw a beautiful error page, and I commented out the cgitb (cgi traceback) line to see how the error message turned into a useless 500 status code.

Please note that I also set in settings.py the registrar, the rotating LGGR file registrar. With this, I found that I needed to do something additional - not shown here --- tell the Python interpreter where the sqlite3 library is located.

Alternatively, you can simply use the print statements that the mentioned flag documents in CGI talk about:

  • With CGI, you will also need to make sure that your code does not contain any print instructions or that sys.stdout is overridden by something that does not write to the HTTP response.

This is true, but it is useful when debugging to see the print record in the HTTP response.

Finally, when I eventually got it working, the browser location window, unfortunately, had something like www.mysite.com/scgi-bin/moc/cgiappserver-prod.cgi/contact in it, whereas I really you just need www. mysite.com/contact.

The exception was the ScriptNameStripper class in cgiappserver-prod.cgi. I got it from other flag documents .

+13
source share

I will try to show what I did and it works in a Godaddy guest account:

In the cgi-bin folder in the MYSITE folder, I added the following cgi file:

 #!/home/USERNAME/.local/bin/python3 from wsgiref.handlers import CGIHandler from sys import path path.insert(0, '/home/USERNAME/public_html/MYSITE/') from __init__ import app class ProxyFix(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ['SERVER_NAME'] = "" environ['SERVER_PORT'] = "80" environ['REQUEST_METHOD'] = "GET" environ['SCRIPT_NAME'] = "" environ['PATH_INFO'] = "/" environ['QUERY_STRING'] = "" environ['SERVER_PROTOCOL'] = "HTTP/1.1" return self.app(environ, start_response) if __name__ == '__main__': app.wsgi_app = ProxyFix(app.wsgi_app) CGIHandler().run(app) 

As you can see, the init file in the MYSITE folder has a flash application.

The most important thing is to correctly set the rights. I installed 755 for this permission of the AS WELL AS folder in the folder "/home/USERNAME/.local/bin/python3" !! Remember that the system needs this permission to open the flask and all python packages.

For debugging, I recommend visiting through your site’s ssh terminal and just running CGI. If this works, but not on the Internet, then you need to grant more permissions or you wrote the wrong .htaccess file.

To open cgi, I have the following .htaccess file in the MYSITE folder:

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

This way it will display the cgi file when someone enters your page.

0
source share

All Articles