heirloom Posted August 4, 2020 Posted August 4, 2020 (edited) I'm having trouble debugging the code from a github repository that works on my machine, but I can't make it work on the server. So I would like to make a virtual machine with the same os and applications to be able to debug the code. I'm doing a flask website. What are the applications that Tommy has installed to deal with flask? Which os? How to install wsgi? Edited August 4, 2020 by heirloom
Krydos Posted August 7, 2020 Posted August 7, 2020 CentOS 7, mod_wsgi-4.6.7. You install mod_wsgi by downloading the source, running ./configure, make, make install. Python 3.7.4. Flask 1.1.1. Let us know if you need more help.
heirloom Posted August 12, 2020 Author Posted August 12, 2020 (edited) I've had some trouble configuring the 'flask' folder. I don't know why I've had to include the location of the python packages in the wsgi file. Or else it said: Exception occurred processing WSGI script '/var/www/flask/myapp.wsgi'. Traceback (most recent call last): File "/var/www/flask/myapp.wsgi", line 6, in <module> from myapp import app as application File "/var/www/flask/myapp/__init__.py", line 1, in <module> from flask import Flask ImportError: No module named flaskAlso although I've installed python 3.7.4 I had to end up using the default Python 3, which is 3.6.8, because I didn't know how to use pip without installing the default. And I couldn't install mod_wsgi from source because it gave me an error, that was something like: 'apxs command not found'. Probably I forgot some dependency. Here I write all the commands I used to deploy flask apps with apache in centos in a similar way as how the Tommy server does it:# VirtualBox guest additionssudo yum install -y epel-release centos-release-sclsudo yum update -ysudo yum install -y make gcc kernel-headers kernel-devel perl dkms bzip2# Devices -> Insert Guest Additions CD image and run itsudo rebootsudo yum install -y dconf-editorbash <(curl -s https://raw.githubusercontent.com/ajr-dev/post-install-script/master/install/settings/gnome.sh) # Install apachesudo yum install -y httpd httpd-devel python3 python3-pip python3-develsudo systemctl start httpdsudo systemctl enable httpd # Install mod_wsgi 4.6.7wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.7.tar.gz"tar -xzf '4.6.7.tar.gz'rm '4.6.7.tar.gz'cd 'mod_wsgi-4.6.7'./configure --with-python=/usr/local/bin/python3makesudo make install # Add this to `/etc/httpd/conf/httpd.conf`# LoadModule wsgi_module modules/mod_wsgi.soapachectl restartsudo cat /var/log/httpd/error_log# If all is okay, you should see a line of the form:# Apache/2.4.6 (CentOS) mod_wsgi/4.6.7 Python/3.6 configured cd ..sudo rm -rf 'mod_wsgi-4.6.7'apachectl restart# Flask Deploy with Apache on CentOSsudo pip3 install flask==1.1.1cd /var/wwwsudo mkdir flaskcd flasksudo mkdir website sudo vi __init__.py from flask import Flask app = Flask(__name__) sudo vi main.py import sys import platform from website import app def linux_distribution(): try: return platform.linux_distribution() except: return "N/A" @app.route("/") def hello(): return """ Hello World!<br><br> <a href="/flask/info/">System Information</a><br> """ @app.route("/info/") def info(): return f""" Python version: {sys.version}<br> dist: {platform.dist()}<br> linux_distribution: {linux_distribution()}<br> system: {platform.system()}<br> machine: {platform.machine()}<br> platform: {platform.platform()}<br> uname: {platform.uname()}<br> """" if __name__ == "__main__": app.run(debug=True)sudo vi website.wsgi import sys sys.path.insert(0, '/var/www/flask') from website import main, app as applicationcd /etc/httpd/conf/sudo cp httpd.conf httpd.conf.baksudo vi httpd.confInsert: <VirtualHost *:80> ServerName localhost WSGIScriptAlias /flask /var/www/flask/website.wsgi <Directory /var/www/flask> Require all granted </Directory> </VirtualHost>apachectl restart # Get IPhostname -I # When visiting 'http://my_host_ip/flask' you should see 'Hello World!'# If you are getting an error you can see it by doingsudo cat /var/log/httpd/error_log Edited August 13, 2020 by heirloom
heirloom Posted August 13, 2020 Author Posted August 13, 2020 (edited) Actually the installed mod_wsgi was using Python 2.7. So I need a way to install the correct version of mod_wsgi. After installing the correct version of mod_wsgi I no longer have to include the location of the packages. mod_wsgi is now using the default Python3 which is 3.6.8. I couldn't get it to run with 3.7.4, even when installing it with --enable-shared it gave 'Error while loading shared libraries' unless I specified the location of the packages in the code like: import site site.addsitedir('/usr/local/lib/python3.7/site-packages') site.addsitedir('/usr/local/lib64/python3.7/site-packages')Install mod_wsgi 4.6.7 with python 3.7.4 in CentOs 7 Edited August 14, 2020 by heirloom
heirloom Posted August 14, 2020 Author Posted August 14, 2020 (edited) In the WSGIScriptAlias the alias should be '/' or else all links inside the application will have to include '/flask/path' and changing all the links in the application is not easy unless you've made them relative to a specific url that you can easily change. This has be done for heliohost anyway. This problem has an answer in Path configuration problem with mod_wsgi - WSGIScriptAlias The way in which the Tommy server is configured is probably using the technique explained there. Edited August 14, 2020 by heirloom
heirloom Posted August 14, 2020 Author Posted August 14, 2020 How do I set up the public_html/flask folder?
Krydos Posted August 15, 2020 Posted August 15, 2020 How do I set up the public_html/flask folder?It explains how to set up the flask directory in the wiki https://wiki.helionet.org/tutorials/flask
heirloom Posted August 15, 2020 Author Posted August 15, 2020 With my current configuration apache won't read the .htaccess file in the folder /home/username/public_html/flask. First I have to setup apache to read from that folder. How do I do that?
Krydos Posted August 16, 2020 Posted August 16, 2020 By default apache ignores .htaccess files. You have to edit the configuration, find the directory block, and change "AllowOverride None" to "AllowOverride All".
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now