Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Flask to run on an apache2
#1
Hi,

I am not sure how to get flask to run on an apache2.
I think my config is already correct.

However, I am not sure about how to Structure my __init__.py, flaskapp.wsgi

This is how my folder structure looks like:

├── flaskapp.wsgi
├── project
│   ├── auth.py
│   ├── __init__.py
│   ├── main.py
│   ├── models.py
│   ├── __pycache__
│   │   ├── auth.cpython-37.pyc
│   │   ├── __init__.cpython-37.pyc
│   │   ├── main.cpython-37.pyc
│   │   └── models.cpython-37.pyc
│   └── templates
│   ├── base.html
│   ├── index.html
│   ├── login.html
│   ├── profile.html
│   └── signup.html
└── setup.py


This my flaskapp.wsgi:

#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/MyApp")

from project import create_app

app = create_app()
if __name__ == "__main__":
    app.run()
and this is my __init__.py:


from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager

db = SQLAlchemy()

def create_app():

    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'secretkeyforyou'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://{user}:{password}@{server}/{database}'.format(
        user='root', password='PYTHON-FORUM', server='localhost', database='USERS')
    db = SQLAlchemy(app)
    db.init_app(app)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))

    # blueprint for auth routes in our app
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    # blueprint for non-auth parts of app
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app
What is it that I am doing wrong?
Is it about the code, which runs locally?

My FlaskApp.cnf

<VirtualHost *:80>
		ServerName rosenheim-cainsdorf.de
		ServerAdmin [email protected]
		WSGIScriptAlias / /var/www/FlaskApp/MyApp/flaskapp.wsgi
		<Directory /var/www/FlaskApp/MyApp/>
			Order allow,deny
			Allow from all
		</Directory>
		ErrorLog ${APACHE_LOG_DIR}/error.log
		LogLevel warn
		CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Reply
#2
Look at this post.

Apache is not what i would recommend at all running Flask.
Two good combination is Gunicorn with Nginx or uWSGI with Nginx.
Digital Ocean guides are good and updated can be applied elsewhere even if not use DO.
How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 20.04
How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 20.04
Reply
#3
(Sep-17-2020, 04:24 PM)snippsat Wrote: Look at this post.

Apache is not what i would recommend at all running Flask.
Two good combination is Gunicorn with Nginx or uWSGI with Nginx.
Digital Ocean guides are good and updated can be applied elsewhere even if not use DO.
How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 20.04
How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 20.04

I followed the pinguin. It is about sql-alchemy, it just will not be installed in the venv. I will change to nginx...
However solutions are still appreciated!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mod-python in apache2 on debian 9 xstation 6 3,806 Jun-15-2020, 01:29 PM
Last Post: DeaD_EyE
  How to deploy Django application on Apache2 server deepag 0 2,039 Jan-23-2019, 05:09 AM
Last Post: deepag

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020