Hey, Simple question so I made my own quick setup guide for a new python web app served by ubuntu 14.04.3 vm, apache 2.4.7 and from source latest mod wsgi (posted below). Im wondering how could I get the app and modwsgi and apache to only run on the system python3.4.3 rather than the default 2.x? It seems my venv isnt connecting properly to modwsgi or something and cant serve the web app because I had to pip install flask into the standard systems python (2.x) to get the configuration to work. So my concern is if I start building/testing 5-10 web projects how is that going to work unless my venv's python is connecting to apache and modwsgi, staying isolated from the system pythons while properly connecting, hence the point of virtual environments.? Im leaning towards python3 rather than legacy python because Ive started with py3, but not sure if it even matters that the app is running on py2 or any conflicts as a result of using 2.x and 3.x on the same app.
************************************************************************************************************************************************************************************************************************ NEW PYTHON WEB APP SETUP INSTRUCTIONS - UBUNTU 14.04 VM / SERVER 0. PREREQUISITES: # on mac you may need xcode-select --install sudo apt-get update / upgrade sudo apt-get install apache2 sudo apt-get install apache2-dev python-dev python3-dev sudo apt-get install mysql-client mysql-server 1. INSTALL MOD_WSGI FROM SOURCE (run from a temp folder, chown it if needed) curl -sL https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz | tar xz cd mod_wsgi-4.4.21 ./configure #( --with-apxs=/usr/local/apache/bin/apxs \ # --with-python=/usr/local/bin/python) make sudo make install make clean # To cleanup after installation make distclean # If you need to build the module for a different version of Apache sudo nano /etc/apache2/mods-available/wsgi.load # create load module file # add the next string to the file: LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so # save, exit, then sudo a2enmod wsgi sudo service apache2 restart 2. CREATE PROJECT STRUCTURE cd /var/www sudo mkdir site1 cd site1 sudo mkdir FlaskApp cd FlaskApp sudo mkdir FlaskApp cd FlaskApp sudo mkdir static templates sudo nano __init__.py # copy text below into file, save, close : from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello, flask app served to client browser properly!" if __name__ == "__main__": app.run(debug=True) 3. SET UP VIRTUAL ENV + INSTALL FLASK sudo apt-get install python3-pip sudo python3.4 -m venv --without-pip venv # pyvenv workaround for ubuntu source venv/bin/activate sudo pip3 install flask sudo python3 __init__.py # run test, check localhost:5000 deactivate # !! have to install flask into system python (python 2.x) or the app wont be served to the browser sudo pip install flask 4. CONFIGURE AND ENABLE A NEW VIRTUAL HOST (one for each new web app) sudo nano /etc/apache2/sites-available/site1.conf # copy lines, save, exit : <VirtualHost *:80> ServerName 192.168.1.112 ServerAlias site1.me ServerAdmin ad...@mywebsite.com WSGIScriptAlias / /var/www/site1/FlaskApp/flaskapp.wsgi <Directory /var/www/site1/FlaskApp/FlaskApp/> Order allow,deny Allow from all </Directory> Alias /static /var/www/site1/FlaskApp/FlaskApp/static <Directory /var/www/site1/FlaskApp/FlaskApp/static/> Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> sudo a2ensite site1 # enable vhost sudo service apache2 reload 5. CREATE .wsgi FILE TO LINK WSGI TO YOUR VHOST sudo nano /var/www/site1/FlaskApp/flaskapp.wsgi # copy lines, save, exit # try? #!/usr/bin/python3.4 #!/usr/bin/python import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/site1/FlaskApp/") from FlaskApp import app as application application.secret_key = 'a7j3sk29dk6gh4n69x0n70nn81mps' 6. RESTART APACHE, SET UP HOSTS FILE ALIAS (MAC), TEST IN BROWSER sudo service apache2 restart # refresh configuration sudo nano /etc/hosts # on MAC add line for your server IP and alias, save, check in browser : ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 192.168.1.112 site1.me SUCCESS ! ************************************************************************************************************************************************************************** -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+unsubscr...@googlegroups.com. To post to this group, send email to modwsgi@googlegroups.com. Visit this group at https://groups.google.com/group/modwsgi. For more options, visit https://groups.google.com/d/optout.