Here's how to spin up a basic Flask app using uwsgi on your Opalstack server:
(This example uses myuser
as the shell user name and myapp
as the app name.)
- Create a new shell user via your Opalstack dashboard. You can use an existing shell user if you want.
- Create a new uwsgi app via your Opalstack dashboard and attach it to whatever website.
- SSH to the server as your shell user and run the following commands to install flask:
cd ~/apps/myapp
source env/bin/activate
pip install flask
- Upload your flask project directory into
~/apps/myapp
. The rest of this example assumes the project directory name is "myproject" containing an empty __init__.py
file and a hello.py
containing the Flask app:
# myproject/hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
- Edit your `uwsgi.ini to change this part...
# adjust the following to point to your project
wsgi-file = /home/myuser/apps/myapp/myproject/wsgihandler.py
touch-reload = /home/myuser/apps/myapp/myproject/wsgihandler.py
... to this:
# adjust the following to point to your project
python-path = /home/myuser/apps/myapp/myproject/
wsgi = hello:app
- Stop the app and restart it:
~/apps/myapp/stop
sleep 2
~/apps/myapp/start
That's it, you're done :-)
The only tricky part here is figuring out the wsgi
directive in your uwsgi.ini
for your own project, but it will usually be projectdir:app
.
If your Flask app isn't organized like the example above then feel free to post here to let me know what you've got and I'll help you wire it up. 🙂