I'm having issues trying to deploy my Flask app on an Amazon EC2 server.
I followed a tutorial here and here as well .
When I go to run my server, after doing sudo apachect1 restart
I get a 500 Internal Error when navigating to my ec2 site. Checking the log I get the following error.
[Tue Jun 20 19:10:48.429468 2017] [wsgi:error] ImportError: No module named flask, referer: http://ec2-<MY-EC2-URL>.amazonaws.com/
Though yet, through the PuTTY I am using to access the EC2 instance, I can see Python and flask are installed doing...
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__
'0.12.2'
Which I thought it/read it may be an issue of not finding my Python path. So I added in my configuration file for apache the python-path=/usr/lib/python2.7
....
000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
WSGIDaemonProcess leu threads=5 python-path=/usr/lib/python2.7
WSGIScriptAlias / /var/www/html/leu/app.wsgi
<Directory leu>
WSGIProcessGroup leu
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Yet still no luck. I've seen a lot with setting up Virtual Environments but I haven't done that. I originally created the project in PyCharm using Python 3.5, but then I went back through the project settings and created it with Python 2.7 and added all the corresponding imports. Still no luck when I did that.
Should I restart again with a virtualenv? Is there something I am missing with setting up Apache?
I was able to get the splash page for Apache saying I set it up correctly.
app.wsgi
import sys
sys.path.insert(0, 'var/www/html/leu')
from app import app as application
Any help?
EDIT: Also tried changing the path to Python in my Apache config file above to /usr/local/lib/python2.7
but still no luck
I know i am way too late....Hope this is useful to someone is struggling!
ServerName your EC2 instance
you have to mention your EC2 instance
使用 sudo -H 安装您的模块。例如 sudo -H pp install flask 如果仍然存在,那么您必须更改配置以使用 python 2.7 而不是 python3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.