SSH to a VPS running ubuntu and installed flask, Apache, and WSGI with the following:
sudo apt-get update
sudo apt-get install python-pip
pip install --user Flask
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi
cloned git repo that had the hello.py program with the following code:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello World!"
if __name__ == '__main__':
app.run(port=5000, debug=True)
created hello.wsgi file in VPS by running the following:
nano hello.wsgi
import sys
sys.path.insert(0, "/var/www/firstapp")
from hello import app as application
created apache configuration pointing to above .wsgi by running the following in VPS:
cd /etc/apache2/sites-available
nano hello.conf
<VirtualHost *>
ServerName example.com
WSGIScriptAlias / /var/www/firstapp/hello.wsgi
WSGIDaemonProcess hello
<Directory /var/www/firstapp>
WSGIProcessGroup hello
WSGIApplicatioinGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Configured Apache to serve Flask application by doing the following in VPS:
sudo a2dissite 000-default.conf
sudo a2ensite hello.conf
sudo servive apache2 reload
if I go to the VPS public IP the application fails with Error 500, when i run "sudo tail -f /var/log/apache2/error.log" I get the error "from flask import Flask ImportError:No module named flask
1 回答
pip install --user
将您的软件包安装到Apache不了解的特定于用户的目录中 . 我建议你use a virtualenv,但如果你能找到它的路径你仍然可以使用你的用户的网站包:然后配置mod_wsgi以使用路径:
虽然建议您使用虚拟环境而不是每用户
site-packages
目录,但如果您确实必须使用每用户site-packages
目录,请使用以下内容: