I have a DO droplet running Fedora with Apache currently configured as a webserver. I need to deploy my simple python app with Flask and Apache. So far I have tried using mod_wsig, and deployment is (predictably) far from simple.
I have got Apache on my server, and it is using https with LetsEncrypt.
I have made a hello-world Flask app that runs on a development server.
I followed the instructions at https://pypi.org/project/mod-wsgi/ and installed mod-wsgi into a python virtual environment. I found the directives needed to configure Apache by running mod_wsgi-express module-config
and put then into the .conf file that modifies the httpd.conf file. (I have created a ‘sites-enabled’ folder that links with a ‘sites-available’ folder)
After that, I was at a loss at what to do, so I have followed https://medium.com/@cdanielmedinas/deploying-your-first-flask-application-on-apache-wsgi-linux-server-fb54537aef41. I have run into problems on issues the tutorial did not cover.
Some I have fixed. Like understanding permissions. Which I think I have fixed by adding the user that is running Apache (as specified in the httpd.conf file) to have execute permissions on the files and folders on the flask app.
Also, I am not sure why the tutorial seemed to not mount the project folder using Alias /project/ /srv/http/your_project
. When I did this, it seemed to fix the “AH01630: client denied by server configuration” problem I had.
Of course there is some more troubleshooting to be done. There seems to be a problem with the .wsgi file as it was suggested to be written in that tutorial I had been following.
Activating the virtual environment by running some activate_this.py file like that tutorial suggests does not seem to work. Now here is the question: Should I remove that section because the virtual environment should be activated in the .conf file that modifies the httpd.conf file by writing WSGIDaemonProcess application_name python-home=/path/to/app/venv
within my .conf file? (https://stackoverflow.com/questions/42661771/how-to-get-mod-wsgi-to-pick-up-my-virtualenv) (Note that I cannot install libapache2-mod-wsgi-py3
like the solution to the stackoverflow question suggests because I am deploying this app on Fedora.)
What should the .wsgi file contain if not that?
I guess the problem is that I haven’t been able to come across a comprehensive guide to deploying a flask app with Fedora+Apache+mod_wsgi that I could make work.
What my question comes down to is this:
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Heya,
The
.wsgi
file is responsible for telling mod_wsgi how to interact with your Flask application. Here’s a simple example for your setup:Replace
/path/to/your/flask/app
and/path/to/your/venv
with the actual paths to your Flask app directory and virtual environment.As for Apache. Your Apache configuration is critical. Below is an example VirtualHost configuration for your Flask app using mod_wsgi:
Breaking Down the Configuration
WSGIDaemonProcess
python-home
.python-path
.WSGIScriptAlias
/
) to your.wsgi
file.Directory Permissions
Logs
SSL Configuration
Also,
The
WSGIDaemonProcess
directive activates the virtual environment for mod_wsgi. Therefore, you do not need to include the virtual environment activation code in your.wsgi
file. Theactivate_this.py
section in your.wsgi
file can be omitted if you specifypython-home
in your Apache configuration.