By Marin Capan
Tech enthusiast
Hi all,
so I have a simple Flask application that I would like to deploy to my Ubuntu 14.04. that is already set as a LAMP server. I have the Apache default configuration with MySQL and both Python 2.7 and 3.7 set up. I have a specific subdomain where I want to deploy my Flask app. I followed this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-apache-mysql-and-python-lamp-server-without-frameworks-on-ubuntu-14-04
But at the end I get a 500 error and when I look at the Apache error log G get that the flask module is not installed which is not true because when I check my virtual enviroment every requirement is there. I made my virtual enviroment with ‘pipenv shell’ and then I installed my requirements with ‘pip install -r requirements.txt’.
Error from the log:
mod_wsgi (pid=3501): Target WSGI script '/var/www/ja.estudent.hr/maktivnosti_backend.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=3501): Exception occurred processing WSGI script '/var/www/ja.estudent.hr/maktivnosti_backend.wsgi'.
Traceback (most recent call last):
File "/var/www/ja.estudent.hr/maktivnosti_backend.wsgi", line 12, in <module>
from maktivnosti_backend import app as application
File "/var/www/ja.estudent.hr/maktivnosti_backend/app.py", line 1, in <module>
from flask import Flask, request, jsonify
ImportError: No module named 'flask'
Here is my setup:
My directory tree:
/var/www/ja.estudent.hr/ |-maktivnosti_backend |-app.py |-maktivnosti_backend.wsgi
My Apache configuration:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAlias www.ja.estudent.hr
ServerName ja.estudent.hr
ServerAdmin webmaster@estudent.hr
#referring the user to the recipes application
DocumentRoot /var/www/ja.estudent.hr/maktivnosti_backend
WSGIScriptAlias / /var/www/ja.estudent.hr/maktivnosti_backend.wsgi
<Directory /var/www/ja.estudent.hr/maktivnosti_backend/>
Require all granted
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.[^.]+\.[^.]+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.ja.estudent.hr/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.ja.estudent.hr/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www.ja.estudent.hr/chain.pem
</VirtualHost>
</IfModule>
My wsgi file:
activate_this = '/home/(username)/.local/share/virtualenvs/maktivnosti_backend-tbfZiu-1/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
#!/usr/bin/python
import sys
import logging
import site
sys.path.append('/home/(username)/.local/share/virtualenvs/maktivnosti_backend-tbfZiu-1/lib/python3.7/site-packages')
site.addsitedir('/home/(username)/.local/share/virtualenvs/maktivnosti_backend-tbfZiu-1/lib/python3.7/site-packages')
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/ja.estudent.hr/')
from maktivnosti_backend import app as application
application.secret_key = '(my secret key)'
If anyone can help me solve this problem I would really apreciate it!
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!
I have the same issue with flask not being recognized as an installed dependency and I am using apache2 and ubuntu 20.04 as well as pipenv. Did you solve this issue?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.