Git Product home page Git Product logo

passenger-python-flask-demo's Introduction

Passenger: Flask example app

This is a Flask hello world example app for the Passenger application server.

The master branch contains the code without Passenger installed.

The end_result branch contains the code with Passenger installed.

Run git diff origin/master..origin/end_result to see what's different.

passenger-python-flask-demo's People

Contributors

foobarwidget avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

passenger-python-flask-demo's Issues

No module named 'flask'

/usr/share/passenger/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import sys, os, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
Traceback (most recent call last):
File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in
app_module = load_app()
File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
return imp.load_source('passenger_wsgi', startup_file)
File "/usr/lib/python3.9/imp.py", line 171, in load_source
module = _load(spec)
File "", line 711, in _load
File "", line 680, in _load_unlocked
File "", line 855, in exec_module
File "", line 228, in _call_with_frames_removed
File "/var/www/power_flask/powerhome_flask/passenger_wsgi.py", line 1, in
from app import app as application
File "/var/www/power_flask/powerhome_flask/app/init.py", line 3, in
from flask import Flask
ModuleNotFoundError: No module named 'flask'

Issue in NginX/Passenger/Flask app/Ubuntu 16.04 online Tutorial: setup not working

Issue report

Question 1: What is the problem?:
I want to install Nginx and Passenger on Ubuntu 16.04 to run python apps e.g. using Flask and I run into issues. When I visit my server http://hXXXXXXX.stratoserver.net/ in the browser I am getting:

We're sorry, but something went wrong.

Question 2: Passenger version and integration mode:
Passenger open source 6.0.4 + Nginx

Question 3: OS or Linux distro, platform (including version):
Ubuntu 16.04 LTS

$ uname -a
Linux hXXXXXXX.stratoserver.net 4.4.0-042stab141.3 phusion/passenger#1 SMP Fri Nov 15 22:45:34 MSK 2019 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.6 LTS
Release:	16.04
Codename:	xenial

Question 4: Passenger installation method:
Nginx + Phusion APT repo

Question 5: Your app's programming language (including any version managers) and framework (including versions):
Python 3.7.6 + Flask 1.1.1

Question 6: Are you using a PaaS and/or containerization? If so which one?
NA

Question 7: Anything else about your setup that we should know?
I have a VPS at strato.nl with Ubuntu 16.04 installed, and the host address is: http://hXXXXXXX.stratoserver.net/ and I was following "Deploying a Python app with Passenger to production" tutorial with the following infrastructure:

Linux/Unix
Nginx
Passenger open source
Python installed via LinuxBrew
Passenger installed on Ubuntu 16.04 LTS
Demo Flask app from github

So the demo Flask app was cloned like this:
git clone https://github.com/phusion/passenger-python-flask-demo.git

Running passenger-memory-stats gives:

$ sudo /usr/sbin/passenger-memory-stats
Version: 6.0.4
Date   : 2020-01-29 13:12:15 +0100
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.


---------- Nginx processes -----------
PID    PPID   VMSize    Private  Name
--------------------------------------
23320  1      174.9 MB  0.8 MB   nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
23325  23320  174.9 MB  0.8 MB   nginx: worker process
### Processes: 2
### Total private dirty RSS: 1.54 MB


----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------
23309  445.7 MB  2.5 MB   Passenger watchdog
23312  672.3 MB  7.5 MB   Passenger core
### Processes: 2
### Total private dirty RSS: 9.98 MB

When I run the app locally on the server everything works as expected:

$ python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Then in another terminal:

$ curl localhost:5000
<!DOCTYPE html>
<html>
<head>
  <title>Hello</title>
  <style>
    html, body {
      font-family: sans-serif;
      background: #f0f0f0;
      margin: 4em;
    }

    .main {
      background: white;
      border: solid 1px #c0c0c0;
      border-radius: 8px;
      padding: 2em;
    }
  </style>
</head>
<body>

  <section class="main">
    <h1>Hello world!</h1>
    <p>Welcome to the Passenger Flask example app.</p>
  </section>

</body>
</html>

So it looks like locally all works fine.
However when I visit http://hXXXXXXX.stratoserver.net/ in the browser I got an error page like described above.

The nginx error /var/log/nginx/error.log:


App 29730 output: Traceback (most recent call last):
App 29730 output:   File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>
App 29730 output:
App 29730 output: app_module = load_app()
App 29730 output:   File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
App 29730 output:
App 29730 output: return imp.load_source('passenger_wsgi', startup_file)
App 29730 output:   File "/var/www/demoapp/code/passenger_wsgi.py", line 3, in <module>
App 29730 output:
App 29730 output: from app import MyApp as application
App 29730 output:   File "/var/www/demoapp/code/app.py", line 1, in <module>
App 29730 output:
App 29730 output: from flask import Flask, render_template
App 29730 output: ImportError
App 29730 output: :
App 29730 output: No module named flask

It seems the server uses Python2 by default.
I need it to use Python3 where I installed Flask.
How can I setup the Python version and Python libraries in Nginx/Passenger?

My demoapp.conf is:

$ vi /etc/nginx/sites-enabled/demoapp.conf
server {
    listen 80;
    server_name hXXXXXXX.stratoserver.net;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/demoapp/code/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_app_env development;
    passenger_friendly_error_pages off;
    passenger_user demoapp;

}

What are the passenger / Nginx settings that I need to set to successfully run a Flask application?
How can I set Passenger/Nginx to use Python3 and Python3 libraries?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.