mod wsgi versions

945 views
Skip to first unread message

Jaqen Nki

unread,
Feb 29, 2016, 5:25:17 AM2/29/16
to modwsgi
Hey, Im following a basic development series here and developing an ubuntu VM (finally going smooth):

https://www.youtube.com/watch?v=Lv1fv-HmkQo&list=PLQVvvaa0QuDc_owjTbIY4rbgXOFkUYOUB
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps

 I was just curious is version of modwsgi (4.4.22 windows, 3.5 linux?)  How to upgrade it on ubuntu ?    when I run    

sudo apt-get install libapache2-mod-wsgi          then         apt-cache showpkg libapache2-mod-wsgi

I get

Provides:
3.4-4ubuntu2.1.14.04.2 - httpd-wsgi
3.4-4ubuntu2 - httpd-wsgi



Graham Dumpleton

unread,
Feb 29, 2016, 5:31:46 AM2/29/16
to mod...@googlegroups.com
The situation with some Linux distributions is absolutely pathetic. The version of mod_wsgi they supply in their own system packages is ancient and there is zero you can do about it besides uninstall their package for mod_wsgi and install mod_wsgi from source code yourself.

If you are just playing around at this point, I would suggest you first use mod_wsgi-express. This can be installed using Python ‘pip’ into a Python virtual environment very easily. You can then run mod_wsgi-express on the command line without having to know anything about how to configure Apache. For more details see:


Other instructions for how to build mod_wsgi from source code can be found at:


The instructions are showing their age, so if have issues with following them, post a followup. Best though to see if you can use mod_wsgi-express initially if just want something to develop and learn with.

Graham

Jaqen Nki

unread,
Feb 29, 2016, 10:32:15 PM2/29/16
to modwsgi
Ok, so I tried the express method - Deleted the flaskapp.wsgi, and FlaskApp.conf (vhost) files from the digitalocean guide (which worked for serving my init.py). 

Created a   venv   at   /var/www/site1/FlaskApp/FlaskApp    activated it,  then I pip3 install flask, mod_wsgi (4.4.22).

All seems well then I run

mod_wsgi-express start-server           :

Server URL         : http://localhost:8000/
Server Root        : /tmp/mod_wsgi-localhost:8000:1000
Server Conf        : /tmp/mod_wsgi-localhost:8000:1000/httpd.conf
Error Log File     : /tmp/mod_wsgi-localhost:8000:1000/error_log (warn)
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : en_US.UTF-8

I go to    http://localhost:8000/   but nothing is there.  

I was hoping this would be as easy as the copy paste method from the guide.  My vm is ubuntu 14 with just    apt-get install apache2    and    apt get install apache2-dev run.
Maybe Ill just stay with the ubuntu vps method but install the latest mod wsgi from source.  What would you do? 

Graham Dumpleton

unread,
Feb 29, 2016, 10:37:19 PM2/29/16
to mod...@googlegroups.com
Where are you running this.

In the first instance you want to be doing this on your local machine to verify you understand how it works.

If you then want to deploy to a VM on DigitalOcean a bit more work is involved.

You would have to be able to understand how to configure Linux to add new services yourself. Knowing that you can follow guidelines in section 'Running mod_wsgi express as root’ to generate a fixed configuration which is then invoked from the Linux startup scripts.

I would suggest just work on your local machine first to get it going for development.

Graham

Jaqen Nki

unread,
Feb 29, 2016, 10:54:13 PM2/29/16
to modwsgi
sorry yeah Im running this on my local ubuntu vm within mac, I ssh from mac terminal to the VM, so its emulating a digitalocean ubuntu server. 

I was able to get it configured right using the guide, and serve my test site with a hello world __init__.py  . 

Although ubuntus apt-get installs modwsgi 3.4 so I wanted to get the same result using the latest version of modwsgi.  Ill try installing from source and see how it goes.

Graham Dumpleton

unread,
Feb 29, 2016, 11:01:21 PM2/29/16
to mod...@googlegroups.com
Is the VM configuration setup to forward port 8080. If it isn’t then localhost:8080 will not work from your Mac browser.

What happens if within the VM you run ‘curl localhost:8080’?

What happens if you replace ‘localhost’ with the IP of your VM?

Graham

Jaqen Nki

unread,
Mar 1, 2016, 4:43:08 AM3/1/16
to modwsgi
sorry had to take a break got frustrated. figured it out, got the newest version from source and used the config method instead of express.  heres how:


INSTALLING FROM SOURCE:

curl -sL https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz | tar xz

tar xvfz mod_wsgi-4.4.22.tar.gz                #unpack if needed

./configure        #( --with-apxs=/usr/local/apache/bin/apxs \
                  #    --with-python=/usr/local/bin/python )
make
sudo make install




        # Location of module: install src/server/.libs/mod_wsgi.so   --->   /usr/lib/apache2/modules/mod_wsgi.so

sudo nano /etc/apache2/mods-available/wsgi.load

        # add the next string to the file:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

            # save, then

sudo a2enmod wsgi
sudo service apache2 restart


       then from guide created vhost and .wsgi files:   site1.conf      flaskapp.wsgi

I was curious if I want to remove the mod_wsgi package and rebuild it to use python3.4 instead of 2.x whats the cleanest way to delete it?
Im also wondering if theres ways to tweak this process better for example not having to do this whole process of configuration for every website I make.

Thanks finally getting somewhere




Graham Dumpleton

unread,
Mar 1, 2016, 4:48:10 AM3/1/16
to mod...@googlegroups.com

> On 1 Mar 2016, at 8:43 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> sorry had to take a break got frustrated. figured it out, got the newest version from source and used the config method instead of express. heres how:
>
>
> INSTALLING FROM SOURCE:
>
> curl -sL https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz | tar xz
>
> tar xvfz mod_wsgi-4.4.22.tar.gz #unpack if needed
>
> ./configure #( --with-apxs=/usr/local/apache/bin/apxs \
> # --with-python=/usr/local/bin/python )
> make
> sudo make install
>
>
>
>
> # Location of module: install src/server/.libs/mod_wsgi.so ---> /usr/lib/apache2/modules/mod_wsgi.so
>
> sudo nano /etc/apache2/mods-available/wsgi.load
>
> # add the next string to the file:
>
> LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
>
> # save, then
>
> sudo a2enmod wsgi
> sudo service apache2 restart
>
>
> then from guide created vhost and .wsgi files: site1.conf flaskapp.wsgi
>
> I was curious if I want to remove the mod_wsgi package and rebuild it to use python3.4 instead of 2.x whats the cleanest way to delete it?

Just replace the installed /usr/lib/apache2/modules/mod_wsgi.so with the newer one. That is the only installed file from mod_wsgi. If rebuilding from source code make sure you use fresh source code, or run ‘make distclean’ in source code before running ‘configure’ again.

> Im also wondering if theres ways to tweak this process better for example not having to do this whole process of configuration for every website I make.

That is the nature of setting boxes up unfortunately. This is where people use tools such as Ansible to script up the setup of new boxes or sites within an existing Apache so they don’t have to do it by hand.

Use of Docker, especially in conjunction with a PaaS which provides automation for deploying sites can make it somewhat simpler.

Graham
Message has been deleted

Jaqen Nki

unread,
Mar 23, 2016, 4:38:46 AM3/23/16
to modwsgi
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 or the 3.4 venv I set up rather than the default system 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)
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 !


**************************************************************************************************************************************************************************

Graham Dumpleton

unread,
Mar 23, 2016, 5:23:11 AM3/23/16
to mod...@googlegroups.com
When building mod_wsgi from source code did you try:

    ./configure --with-python=python3

Ensure you first do a:

    make distclean

to clear out old build from source directory if you have done a prior build in the directory.

If you need an ability during development to be able to use either Python 2 or Python 3, consider using mod_wsgi-express.


Graham

--
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+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Jaqen Nki

unread,
Mar 24, 2016, 2:34:20 AM3/24/16
to modwsgi
Ok so my issue was on ./configure  I entered --with-python=/usr/local/lib/python3.4 rather than just python3.  I deleted flask from system python, and left flask installed into python3 - it now serves the page properly!  My venv is using 3.4.  The vhost flask app is working fine.  this line in the .wsgi file makes me curious though:

#!/usr/bin/python

Would this shebang line call the python2.x to run the .conf and .wsgi files.  Dont see how it could matter because apparently the app is running fine with 3.4.  Anyways thanks.

Graham Dumpleton

unread,
Mar 24, 2016, 2:38:29 AM3/24/16
to mod...@googlegroups.com

> On 24 Mar 2016, at 5:34 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> Ok so my issue was on ./configure I entered --with-python=/usr/local/lib/python3.4 rather than just python3. I deleted flask from system python, and left flask installed into python3 - it now serves the page properly! My venv is using 3.4. The vhost flask app is working fine. this line in the .wsgi file makes me curious though:

If giving full path, and it was in /usr/local/bin, would have been:

./configure --with-python=/usr/local/bin/python3.4

That is, path to Python executable, not the library directory.

Using ‘python3’ meant it would have used whatever was found in your PATH, which I presumed is what you wanted.

>
> #!/usr/bin/python
>
> Would this shebang line call the python2.x to run the .conf and .wsgi files. Dont see how it could matter because apparently the app is running fine with 3.4. Anyways thanks.

The #! line in a WSGI script file is not relevant. You generally do not include it in a WSGI script file.

It is not needed because mod_wsgi is compiled against and links to a specific Python version/installation and that is what dictates what is used.

Graham

Jaqen Nki

unread,
Mar 24, 2016, 2:55:27 AM3/24/16
to modwsgi
Great that cleared everything up perfect. 
Message has been deleted

Jaqen Nki

unread,
Apr 27, 2016, 12:02:04 AM4/27/16
to modwsgi
Hey new issue.  Wonder if you have any experience with pymysql or oracle myql connector python for connecting python3 web app to mysql.  Stuck at this part in my course: https://pythonprogramming.net/flask-connect-mysql-using-mysqldb-tutorial/     Saw some wsgi errors in apache error.log so heres my post:

How can I import a dbconnection function in PyMySQL like MySQLdb (which works)? Ive tried this and my app is broken. :

dbconnect.py file (to be used in different parts of web app) :


import pymysql

def connection():
    conn = pymysql.connect(host = "localhost",
                           user = "root",
                           passwd = "mysqlroot",
                           db = "sqltest")

    c = conn.cursor()
    return c, conn



init.py web app file (testing the module on register page):


from dbconnect import connection

@app.route('/register/', methods=["GET","POST"])
def register_page():
    try:
        c, conn = connection()
        return("okay, flask to db connection appears to be working")
    except Exception as e:
        return(str(e))


EDIT: calling the connection() function works with MySQLdb module but not with pymysql or mysql.connector, it just makes no sense and very frustrating.   Heres apache error log after above connection attempt (says ImportError no module "dbconnect" yet there is and once Im in python3 shell I can import it fine) :


[Tue Apr 26 21:48:02.125650 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] mod_wsgi (pid=23265): Target WSGI script '/var/www/site1/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://site1.me/


[Tue Apr 26 21:48:02.125714 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] mod_wsgi (pid=23265): Exception occurred processing WSGI script '/var/www/site1/FlaskApp/flaskapp.wsgi'., referer: http://site1.me/


[Tue Apr 26 21:48:02.125739 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] Traceback (most recent call last):, referer: http://site1.me/


[Tue Apr 26 21:48:02.125856 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] File "/var/www/site1/FlaskApp/flaskapp.wsgi", line 6, in , referer: http://site1.me/


[Tue Apr 26 21:48:02.125861 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] from FlaskApp import app as application, referer: http://site1.me/


[Tue Apr 26 21:48:02.125933 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] File "/var/www/site1/FlaskApp/FlaskApp/init.py", line 2, in , referer: http://site1.me/


[Tue Apr 26 21:48:02.125938 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] from dbconnect import connection, referer: http://site1.me/


[Tue Apr 26 21:48:02.125954 2016] [wsgi:error] [pid 23265:tid 139993628493568] [client 192.168.1.100:53645] ImportError: No module named 'dbconnect', referer: http://site1.me/

Graham Dumpleton

unread,
Apr 27, 2016, 12:41:32 AM4/27/16
to mod...@googlegroups.com
Since dbconnect is your module file, it looks like you haven’t configured mod_wsgi to extend the Python module search path to include the directory that file is found in.

How are you configuring mod_wsgi?

Graham

Message has been deleted

Jaqen Nki

unread,
Apr 27, 2016, 1:11:00 AM4/27/16
to modwsgi
Good question.  I was curious about this too.  In the tutorial theres no extra configuration needed (simply installed modwsgi --with-python=python3 from source, setup a vhost and a .wsgi file, and my site is auto served once the server boots up).  I tested this by starting python3 shell from inside then outside of the FlaskApp folder (containing the init.py file and project files). 

In the shell, sitting within the project folder, I can import dbconnect just fine (as should the init.py file since its in the folder).

But outside of the project FlaskApp folder the import is not found.  I figured this shouldnt matter since the init.py file is the only file importing from dbconnect.py, all within the project folder.  Not sure if it matters but heres the packages in python3 lib:

/usr/local/lib/python3.4/dist-packages$ ls

flask                  Flask_WTF-0.12.egg-info     jinja2                pymysql                  Werkzeug-0.11.4.dist-info
Flask-0.10.1.egg-info  itsdangerous-0.24.egg-info  Jinja2-2.8.dist-info  PyMySQL-0.7.2.dist-info  wtforms
flask_wtf              itsdangerous.py             __pycache__           werkzeug                 WTForms-2.1.egg-info

Graham Dumpleton

unread,
Apr 27, 2016, 1:24:56 AM4/27/16
to mod...@googlegroups.com
When using mod_wsgi it will not look in the directory where the WSGI script file is, by default, for other modules to import. When you run from command line, python will look in current working directory.

You there need to tell mod_wsgi how to find your application and modules. I can't easily check right now, but thought Flask deployment guide for mod_wsgi explained that.

Ways to do it are to update sys.path in WSGI script file. If using embedded mode use WSGIPythonPath directive and if using daemon mode use python-path option to WSGIDaemonProcess directive.

Knowing what to look for, check back the Flask docs for mod_wsgi deployment, I can't get to them right now.

Graham
Message has been deleted

Graham Dumpleton

unread,
Apr 27, 2016, 2:04:19 AM4/27/16
to mod...@googlegroups.com
Should not have anything to do with differences between Python 2 and Python 3.

Where are the files init.py and dbconnect.py located? What else is in that directory?

Have you verified that mod_wsgi is using the correct Python version? You can do this by printing out sys.version from the WSGI script file and looking in Apache logs.

Graham

On 27 Apr 2016, at 11:14 AM, Jaqen Nki <proj...@gmail.com> wrote:

Youre right.  Just tested that pymysql can connect to db first off, and it works.  So the problem lies as you said in wsgi not finding the module or python3 path.  In the tutorial I believe hes using default python 2.7 so he doesnt need further configuration, because by default mod wsgi probably finds python2.7 path.  So I need to figure out how to get modwsgi to point to the right place, which Im not sure on.  When I installed it from source it installed --with-python3 option so Im not sure why it doesnt use that python as the default path. Heres my wsgi and vhost files anyways (and Ill do a little digging in the mean time.  Dont mean to be a bother, just this issue was very confusing as I thought the problem lay with pymysql, yet its modwsgi.  Until this import issue my web app has been working perfectly):

/var/www/site1/FlaskApp$ cat flaskapp.wsgi

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'


kien1@kien1pv:/etc/apache2/sites-enabled$ cat site1.conf

<VirtualHost *:80>
                ServerName 192.168.1.105

                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 /var/www/site1/logs/error.log
                LogLevel warn
                CustomLog /var/www/site1/logs/access.log combined
</VirtualHost>
Message has been deleted
Message has been deleted

Jaqen Nki

unread,
Apr 27, 2016, 4:30:33 AM4/27/16
to modwsgi
Wow so I tried many different ways of printing sys.version at the end of flaskapp.wsgi :

print(sys.version)
print(sys.version_info)
return(sys.version)

import platform
print(platform.python_version)

input()

Nothing worked, it will not print it, I checked the apache access and error log.
But I deleted pycache then restarted server and a new pycache appeared with cpython34 so it would appear that python3.4 is in fact running.

Project structure is as follows:


/var/www/site1/:

|--------FlaskApp |----------------FlaskApp |------------------------static |------------------------templates |------------------------venv |------------------------__init__.py
|------------------------dbconnect.py
|------------------------__pycache__ contains __init__.cpython-34.pyc
|----------------flaskapp.wsgi

Graham Dumpleton

unread,
Apr 27, 2016, 4:30:45 AM4/27/16
to mod...@googlegroups.com
Try a relative import.

Instead of:

    from dbconnect import connection

use:

    from .dbconnect import connection

Graham

On 27 Apr 2016, at 1:58 PM, Jaqen Nki <proj...@gmail.com> wrote:

Wow so I tried 3 different ways of printing sys.version at the end of flaskapp.wsgi :

print(sys.version)
print(sys.version_info)

import platform
print(platform.python_version)


Nothing worked, it will not print it, I checked the apache access and error log.
But I deleted pycache then restarted server and a new pycache appeared with cpython34 so it would appear that python3.4 is in fact running.

Project structure is as follows:

/var/www/site1/:

|--------FlaskApp |----------------FlaskApp |------------------------static |------------------------templates |------------------------venv |------------------------__init__.py
|------------------------dbconnect.py
|------------------------__pycache__ contains __init__.cpython-34.pyc
|----------------flaskapp.wsgi

Jaqen Nki

unread,
Apr 27, 2016, 4:39:28 AM4/27/16
to modwsgi
OH MY FKING GOD it worked...  how the hell...  literally one period had me hung up for over a week.  Unbelievable...  Thanks man didnt know about a relative import.  Youre the man!

Graham Dumpleton

unread,
Apr 27, 2016, 4:41:52 AM4/27/16
to mod...@googlegroups.com

> On 27 Apr 2016, at 2:09 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> OH MY FKING GOD it worked... how the hell... literally one period had me hung up for over a week. Unbelievable... Thanks man didnt know about a relative import. Youre the man!

Python 2.7 still supports absolute import for a module within a package from other code in the same package.

In Python 3.?+, absolute imports within a package has to be enabled and should use relative import when import modules from same package. If you don’t use a relative import, you would need to have given full package module path, which is a bad idea.

Graham

Jaqen Nki

unread,
May 11, 2016, 2:44:07 AM5/11/16
to modwsgi
Hey, just had a question about working with venvs in python web development.

So far Ive been working on my first site, its going good (except getting stuck on a CMS for my flask app).  Once Im about done Im going to build another 2 sites, which will probably use django, my next tutorial series to tackle.  So obviously I need to use venv to separate each site project's packages and stuff to prevent conflicts and problems.

Whats interesting is on ubuntu it appears there are 3 pythons in use.  Default 2x, and 3x, with their packages here :  /usr/lib/python2.7/dist-packages    /usr/lib/python3/dist-packages

and the python3 Im using is here, and has all the packages Im using for my current site:

$ ls /usr/local/lib/python3.4/dist-packages

flask                    itsdangerous-0.24.egg-info            passlib                         PyMySQL-0.7.2.dist-info    WTForms-2.1.egg-info
Flask-0.10.1.egg-info          itsdangerous.py             passlib-1.6.5.dist-info  werkzeug
flask_wtf                              jinja2                      __pycache__                      Werkzeug-0.11.4.dist-info
Flask_WTF-0.12.egg-info   Jinja2-2.8.dist-info        pymysql                        wtforms

Ive activated my venv and pip3 installed these packages yet when I open the venv folder within FlaskApp it shows no files in site-packages : 

/var/www/site1/FlaskApp/FlaskApp/venv/lib/python3.4/site-packages

as they are being installed to /usr/local/lib/python3.4/dist-packages - it seems with my current config the interpreter in venv serves no purpose as its not running the app.

So I want to figure out how to keep future projects properly isolated, but still served up automatically when the server boots up, as its very convenient to configure once, set and forget.  Im a little lost on how to set up venvs properly as it seems when I configured mod wsgi it installed it to the default python3.  Maybe I can run a pip3 freeze on current python3.4 :

pip3 freeze
pip3 freeze > requirements.txt

then install these into a new project venv for a 2nd website employing another flaskapp:

pip3 install -r requirements.txt


I got a feeling Ill have to revamp this whole configuration and use standalone wsgi configs which is a hassle.  Any help is appreciated thanks.

Graham Dumpleton

unread,
May 11, 2016, 2:55:09 AM5/11/16
to mod...@googlegroups.com
If packages are being installed to /usr/local/lib/python3.4/dist-packages then it is indeed skipping the virtual environment.

What command are you using to create the virtual environment and then activate it?

Are you using virtualenv or trying to use pyvenv which is now bundled with recent Python 3 versions?

Are you by chance running pip with sudo? You shouldn’t be.

After activating the virtual environment, what do you get when you run:

   which python
   which python3
   which pip
   which pip3

Graham

Message has been deleted

Jaqen Nki

unread,
May 11, 2016, 3:22:25 AM5/11/16
to modwsgi
Pyvenv is actually broken on ubuntu 14, so I use this workaround:


sudo python3.4 -m venv --without-pip venv

Ive used   sudo pip3 install flask   pip3 install flask         and they both install to the same place and heres the which commands:


(venv) kien1@kien1pv:/var/www/site1/FlaskApp/FlaskApp$ which python
/usr/bin/python
(venv) kien1@kien1pv:/var/www/site1/FlaskApp/FlaskApp$ which python3
/usr/bin/python3
(venv) kien1@kien1pv:/var/www/site1/FlaskApp/FlaskApp$ which pip
/usr/bin/pip
(venv) kien1@kien1pv:/var/www/site1/FlaskApp/FlaskApp$ which pip3
/usr/bin/pip3


Heres some info I found describing exactly the pyvenv issue.  Maybe I can see if ubuntu 16 has this fixed, and test pyvenv on that version.



https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847


1) User wants to pip install something into their ~/.local directory. Having python3-* packages installed does not give them pip3. They have to apt-get install python3-pip. If they try to `pip3 install foo` it will try to install it into the system dist-packages and this will fail with a permission denied. They must `pip3 install --user foo` and it will end up in their ~/.local/lib/pythonX.Y/site-packages directory, and it will be importable by the system Python. All of this works right out of the box today:
% pip3 install --user nose2
[...]
% python3.4 -c "import nose2; print(nose2)"
<module 'nose2' from '/home/barry/.local/lib/python3.4/site-packages/nose2/__init__.py'>
2) User wants to pip install something into the system package path. Again they must install python3-pip, and this time they must use `sudo pip3 install foo`. foo gets installed into /usr/local/lib/python3.4/dist-packages. All of this works right out of the box today:
% sudo pip3 install nose2
[...]
% python3.4 -c "import nose2; print(nose2)"
<module 'nose2' from '/usr/local/lib/python3.4/dist-packages/nose2/__init__.py'>
3) Use creates a virtualenv and wants to install foo into the virtualenv. Regardless of whether --system-site-packages is used or not, and regardless of whether pyvenv-3.4 or virtualenv is used, the virtualenv should already contain `/my/venv/bin/pip` and the user should be able to enter the venv and run `pip install foo`. This should install foo into /my/venv/lib/pythonX.Y/site-packages and have it be importable.
This latter is the use case that's currently broken with pyvenv-3.4 due to the disabling of ensurepip, so this is the use case we need to fix. System pip package shouldn't enter into the picture. The question we have to answer, IMHO, is whether we want ensurepip to use the recursively bundled pip (and its dependencies) or to rewheel system pip and dependencies (in which case we'd need to handle the circular apt dependencies from python3.4->python3-pip).
I think the determining factor should be Debian policy w.r.t. build-from-source. Wheels are just zips so unzipping the two bundled wheels results in all the recursive source files contained within the wheels. But how are the wheels built to be included in the tarball? That recipe must be embodied in the Debian package so that the bundled wheels (with their own vendored libraries) can be completely reproduced from upstream source.
If it's not possible to do that reproducibly, then we need an approach like rewheel.


Graham Dumpleton

unread,
May 11, 2016, 3:52:01 AM5/11/16
to mod...@googlegroups.com
Why are you using:

sudo python3.4 -m venv --without-pip venv

vs:

python3.4 -m venv

The whole point of virtual environments is that you create them as your own user. You don’t want to create it as root.

Also, why use —without-pip?

You want pip to be installed so that after you activate the virtual environment you can then run pip from the virtual environment to install packages in that same virtual environment.

Jaqen Nki

unread,
May 11, 2016, 4:04:41 AM5/11/16
to modwsgi
For sure, the only reason I did that is because pyvenv and venv were broken on ubuntu 14, and without sudo  and --without-pip the command would fail.  What Im going to do is create another VM image running ubuntu 16, which has improved python3 support, and test my website and pyvenv on there.  And I will get back to you, probably tomorrow. 

If pyvenv works I wonder if its possible to install from source mod wsgi directly into the venv python interpreter, avoiding system python conflicts altogether.

./configure        #( --with-apxs=/usr/local/apache/bin/apxs \
                  #    --with-python=python3  specify py3)

Graham Dumpleton

unread,
May 11, 2016, 4:49:05 AM5/11/16
to mod...@googlegroups.com
You can try the pip installable mod_wsgi version:

    pip install mod_wsgi

Details at:


That will give you mod_wsgi-express which you can use from the command line to start up a Apache/mod_wsgi instance on a non privileged port as a non root user.

For trying things out this is the easiest way to get going.

If need be you can then use mod_wsgi-express to either install the Apache module into your Apache installation, or it can tell you what LoadModule line to use to load it direct from the Python virtual environment.

Suggest you perhaps try mod_wsgi-express on the command line first as it worries about all the configuration for you.

Graham



Jaqen Nki

unread,
May 11, 2016, 8:37:40 AM5/11/16
to modwsgi
Cool so ubuntu 16 is running very smooth, all updated software dists, and seems faster.  Pyvenv is fixed and have all my packages installed in the venv.  I used

pip3 install mod-wsgi     then ran express start, works fine on port 8000, and testinit.py works on port 5000

Now for the apache2 config.  Id like it to behave like Ive had, set and forget, just boot up server and hit up my host browser - rather than have to run CLI commands everytime I boot server.  Not really sure how modwsgi express is convenient /practical for development and definitely not in a production environment, when someone can configure once.

Now I just need to figure how to connect apache to the venv with modwsgi.  Thanks almost there.

Graham Dumpleton

unread,
May 11, 2016, 8:48:34 AM5/11/16
to mod...@googlegroups.com
There is a way of having mod_wsgi-express just generate all the configuration and save it. You could then just start it up with the already setup configuration from a system init script. This is partly explain on the PyPi page.

If you are already familiar though with integrating mod_wsgi into the main Apache, what you can do is after having created your virtual environment and installed mod_wsgi into using pip, run:

    sudo mod_wsgi-express install-module

That will copy the compiled mod_wsgi.so into the modules directory of your Apache installation.

That command should also output a couple of lines which is the Apache configuration snippet you would include in the Apache configuration for loading the mod_wsgi module and setting the correct location for the Python virtual environment you want to use, based on what it was installed into.

So would output something like:

    LoadModule wsgi_module modules/mod_wsgi-py34.so
    WSGIPythonHome /some/path/to/venv

Graham



Message has been deleted

Graham Dumpleton

unread,
May 11, 2016, 8:04:15 PM5/11/16
to mod...@googlegroups.com
Command not found error for what? I don’t see anything relevant in the output you gave below.

Provide a copy of what command you are running and the output.

Graham
 
On 12 May 2016, at 1:09 AM, Jaqen Nki <proj...@gmail.com> wrote:

Hmm Im getting a command not found error, even though mod-wsgi is defintely installed in the venv lib, and apaches working:

 systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Wed 2016-05-11 09:02:24 MDT; 8min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 7700 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 7894 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 7733 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 55 (limit: 512)
   CGroup: /system.slice/apache2.service
           ├─7751 /usr/sbin/apache2 -k start
           ├─7919 /usr/sbin/apache2 -k start
           └─7920 /usr/sbin/apache2 -k start

May 11 09:05:54 k1pvm systemd[1]: Stopped LSB: Apache2 web server.
May 11 09:05:54 k1pvm systemd[1]: Starting LSB: Apache2 web server...
May 11 09:05:54 k1pvm apache2[7733]:  * Starting Apache httpd web server apache2
May 11 09:02:23 k1pvm apache2[7733]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set
May 11 09:02:24 k1pvm apache2[7733]:  *
May 11 09:02:24 k1pvm systemd[1]: Started LSB: Apache2 web server.
May 11 09:06:02 k1pvm systemd[1]: Reloading LSB: Apache2 web server.
May 11 09:06:02 k1pvm apache2[7894]:  * Reloading Apache httpd web server apache2
May 11 09:02:31 k1pvm apache2[7894]:  *
May 11 09:02:31 k1pvm systemd[1]: Reloaded LSB: Apache2 web server.
lines 1-25/25 (END)

Jaqen Nki

unread,
May 11, 2016, 8:18:22 PM5/11/16
to modwsgi
Sorry,  Im getting a command not found error, even though mod-wsgi is defintely installed in the venv lib, and apaches working, both sudo and non sudo:

    sudo mod_wsgi-express install-module
 
sudo: mod_wsgi-express: command not found

mod_wsgi-express: command not found

Graham Dumpleton

unread,
May 11, 2016, 8:39:18 PM5/11/16
to mod...@googlegroups.com
Was that with the Python virtual environment activated?

Usually the PATH should be inherited through the sudo and so it will be found. It is possible your sudo setup is a bit different to what I would expect.

In that case do:

    which mod_wsgi-express

and then:

    sudo /some/path/mod_wsgi-express install-module

where /some/path/mod_wsgi-express is the path that ‘which’ produced.

If ‘which’ can’t find it, you don’t have the virtual environment activated, or something else odd about it.

Jaqen Nki

unread,
May 11, 2016, 11:41:26 PM5/11/16
to modwsgi
        cool, needed that path, and it worked:

$ which mod_wsgi-express

/var/www/site1/FlaskApp/FlaskApp/venv/bin/mod_wsgi-express


(venv) $ sudo /var/www/site1/FlaskApp/FlaskApp/venv/bin/mod_wsgi-express install-module

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so
WSGIPythonHome /var/www/site1/FlaskApp/FlaskApp/venv


Ok so now how do I automate the connection to serve my app, can I skip creating a vhost and .wsgi file?  I need my servers IP 192.168.1.102 to be available on my mac browser. 

Graham Dumpleton

unread,
May 11, 2016, 11:43:32 PM5/11/16
to mod...@googlegroups.com
Follow the normal setup instructions for mod_wsgi in Flask documentation or work it out from:


The Flask documentation is probably the better place to start.

If confused then use mod_wsgi documentation.

Graham

Message has been deleted

Graham Dumpleton

unread,
May 12, 2016, 2:37:12 AM5/12/16
to mod...@googlegroups.com

> On 12 May 2016, at 4:33 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> Ok this is not working, I found a snippet to add to .wsgi file that flask docs said to add for virtualenvs which is good, all my conf files are now setup properly:
>
> /var/www/site1/FlaskApp/flaskapp.wsgi :
>
> activate_venv = '/var/www/site1/FlaskApp/FlaskApp/venv/bin/activate'
> execfile(activate_venv, dict(__file__=activate_venv))
>
> 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'
>
>
> But apache says "ERROR: module wsgi does not exist!" when I try to enable it. (I dont get it because with the earlier command it outputted the location of the installed module) :
>
> sudo a2enmod wsgi

Where did you put that LoadModule and WSGIPythonHome directives that were output by the install-module command?

For a2enmod to work, you would need to have created a ‘wsgi.load’ file in the ‘modules-available’ directory of Apache. All that script would then do is symlink that file into ‘modules-enabled’.

If you had manually added the LoadModule and WSGIPythonHome directives into the Apache configuration you do not need to run a2enmod, just restart Apache.

You also should not need:

activate_venv = '/var/www/site1/FlaskApp/FlaskApp/venv/bin/activate'
execfile(activate_venv, dict(__file__=activate_venv))

as the WSGIPythonHome directive should already have enabled things for the Python virtual environment.

Graham
Message has been deleted
Message has been deleted

Graham Dumpleton

unread,
May 12, 2016, 3:00:42 AM5/12/16
to mod...@googlegroups.com

On 12 May 2016, at 4:56 PM, Jaqen Nki <proj...@gmail.com> wrote:

EDIT:  my bad, had to create wsgi.load file then enable it.  sudo a2enmod wsgi.  Now all my conf files are set up right I think.  Just to be clear, is this where I put the line    

                  WSGIPythonHome /var/www/site1/FlaskApp/FlaskApp/venv

The WSGIPythonHome directive should be placed in the wsgi.load file after the LoadModule line.

For best results also add into end of that file:

WSGIRestrictEmbedded On

sudo nano /etc/apache2/sites-available/site1.conf       

<VirtualHost *:80>
                ServerName 192.168.1.102
                ServerAlias site1.me
                ServerAdmin ad...@mywebsite.com

And again for best results, also add here:

WSGIDaemonProcess flask
WSGIProcessGroup flask
WSGIApplicationGroup %{GLOBAL}

                WSGIScriptAlias / /var/www/site1/FlaskApp/flaskapp.wsgi
                WSGIPythonHome /var/www/site1/FlaskApp/FlaskApp/venv

                <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 /var/www/site1/logs/error.log
                LogLevel warn
                CustomLog /var/www/site1/logs/access.log combined
</VirtualHost>


With this apache wont run.

For what the daemon process directives are about read:


Graham

Jaqen Nki

unread,
May 12, 2016, 3:01:47 AM5/12/16
to modwsgi
K fixed that stuff.  To be clear, where do I put this line, as it cant go in Virtual host file, and with it  at the top of flaskapp.wsgi still get 500 error:

             WSGIPythonHome /var/www/site1/FlaskApp/FlaskApp/venv

Graham Dumpleton

unread,
May 12, 2016, 3:23:21 AM5/12/16
to mod...@googlegroups.com

> On 12 May 2016, at 5:01 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> K fixed that stuff. To be clear, where do I put this line, as it cant go in Virtual host file, and with it at the top of flaskapp.wsgi still get 500 error:
>
> WSGIPythonHome /var/www/site1/FlaskApp/FlaskApp/venv

Check the previous email properly.

I said the WSGIPythonHome directive should be placed in the wsgi.load file after the LoadModule line.

Can you please stop discarding the existing conversation. Keep the discussion together.

Graham

Jaqen Nki

unread,
May 12, 2016, 4:32:40 AM5/12/16
to modwsgi
    Ok my bad, I figured it would be good idea to avoid posting redundancies.  After much struggle GOOD NEWS IT WORKS!  This is awesome, just tested it after reboot linux, it autoserves perfectly.  So I take it for a new project, I repeat the process, new vhost and .wsgi file, and create a wsgi.load file for each site?  Either way I have it all logged in a file so I know exactly what to do next time.  I have two concise guide txt files for setting up a python3 flaskapp on ubuntu server now, one with and one without a venv configuration- if you want to post them in mod wsgi docs as easy setup guides to help other people, let me know (honestly a lot of stuff in the docs is unnecessary and not to the point, one can get lost in the convolution).  Thanks so much for bearing with me man you are a lifesaver and a brilliant programmer, and Im curious to know what projects youre working on or have worked on.

    Im going to throw you an amazon gift card code after I can get to the store soon, for the almost instantaneous responses and solving my problems every time - like do you even sleep? haha.  Also Ill show you my finished web sites once they are live because they are pretty slick and theyre my first projects in web development, of which Im proud.  It may be a couple months but one of the sites is for an upcoming game mod of warcraft 3 (best RTS of all time), which is being cloned to the starcraft 2 engine because the old engine is outdated and clunky - called Armies of Azeroth on moddb.com.  Im probably going to have to resort to django as the go to framework since its more popular and most of the job postings I see are for django developers and rarely flask.  Anyways cheers thanks again hope all is well in AU.

Graham Dumpleton

unread,
May 12, 2016, 4:52:25 AM5/12/16
to mod...@googlegroups.com

> On 12 May 2016, at 6:32 PM, Jaqen Nki <proj...@gmail.com> wrote:
>
> Ok my bad, I figured it would be good idea to avoid posting redundancies. After much struggle GOOD NEWS IT WORKS! This is awesome, just tested it after reboot linux, it autoserves perfectly. So I take it for a new project, I repeat the process, new vhost and .wsgi file, and create a wsgi.load file for each site?

The wsgi.load file should only have in it the LoadModule, WSGIPythonHome and WSGIRestrictEmbedded directives. They applied to the server as a whole and not specific VirtualHosts.

When you talk about adding more VirtualHost’s, that is when you will need to be a bit careful with respect to virtual environments.

First up, a separate VirtualHost is used for each distinct site hostname. Don’t use separate VirtualHost’s if only trying to mount different applications at different sub URLs of the same site. Seen people try and use multiple VirtualHost’s for same site hostname too many times. Is wrong way.

Because you are going to have multiple VirtualHost’s would suggest doing things a little differently.

First up, the wsgi.load file would only have LoadModule and WSGIRestrictEmbedded directives in it. Not WSGIPythonHome.

In that file the WSGIPythonHome was acting as a fallback for both embedded mode and daemon mode. With WSGIRestrictEmbedded set to On, don’t need the fallback. Instead, we want to set python-home for each daemon process group setup using WSGIDaemonProcess directive.

Thus:

# wsgi.load

LoadModule …
WSGIRestrictEmbedded On

# site1.conf

<VirtualHost *:80>
ServerName site1.host.name

WSGIDaemonProcess site1 python-home=/some/path/site1/venv
WSGIProcessGroup site1
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /some/path/site1/app.wsgi

...
</VirtualHost>

# site2.conf

<VirtualHost *:80>
ServerName site2.host.name

WSGIDaemonProcess site2 python-home=/some/path/site2/venv
WSGIProcessGroup site2
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /some/path/site1/app.wsgi

...
</VirtualHost>

If you do need to host multiple applications under same VirtualHost at different sub URLs, you would use something like:

# site3.conf

<VirtualHost *:80>
ServerName site3.host.name

WSGIDaemonProcess site3_main python-home=/some/path/site3_main/venv
WSGIDaemonProcess site3_suburl python-home=/some/path/site3_suburl/venv

WSGIProcessGroup site3
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias /suburl /some/path/site3_suburl/app.wsgi process-group=site3_suburl
WSGIScriptAlias / /some/path/site3_main/app.wsgi

...
</VirtualHost>


> Either way I have it all logged in a file so I know exactly what to do next time. I have two concise guide txt files for setting up a python3 flaskapp on ubuntu server now, one with and one without a venv configuration- if you want to post them in mod wsgi docs as easy setup guides to help other people, let me know (honestly a lot of stuff in the docs is unnecessary and not to the point, one can get lost in the convolution). Thanks so much for bearing with me man you are a lifesaver and a brilliant programmer, and Im curious to know what projects youre working on or have worked on.

The docs are a mess right now, I acknowledge that. The effort required to bring them up to date and better organise them is substantial and more interested in other stuff right now.

> Im going to throw you an amazon gift card code after I can get to the store soon, for the almost instantaneous responses and solving my problems every time - like do you even sleep? haha. Also Ill show you my finished web sites once they are live because they are pretty slick and theyre my first projects in web development, of which Im proud. It may be a couple months but one of the sites is for an upcoming game mod of warcraft 3 (best RTS of all time), which is being cloned to the starcraft 2 engine because the old engine is outdated and clunky - called Armies of Azeroth on moddb.com. Im probably going to have to resort to django as the go to framework since its more popular and most of the job postings I see are for django developers and rarely flask. Anyways cheers thanks again hope all is well in AU.

If you are looking at Amazon gift card, that is much appreciated. Just note that it needs to be the US Amazon store. That store is only one I can readily use even though don’t Iive in the US. I travel there enough though to order stuff and send to friends in US and then pick it up. :-)

Thanks.

Graham

Message has been deleted
Message has been deleted
Message has been deleted

Jaqen Nki

unread,
May 13, 2016, 2:28:10 AM5/13/16
to modwsgi
I see how I should probably structure this for multiple sites now.  Since my server has only one IP, like you said I can do either of two methods, separate vhost for each site (prefixed domains, or combined into one (sub domains).  Heres the configs I came up with, I will have to test it with a new project to see if it works:

                                            VHOST CONFIGURATION - MULTIPLE SITES                                                   
                                               
        # wsgi.load
       
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so
WSGIRestrictEmbedded On
                                       
                                               
    METHOD 1:    Separate virtual host per project  -  site1  site2                                             
                               
                                # site1.conf

<VirtualHost *:80>
    ServerName site1.192.168.1.102
    ServerAlias    site1.me
   
    WSGIDaemonProcess site1 python-home=/var/www/site1/
FlaskApp/FlaskApp/venv

    WSGIProcessGroup site1
    WSGIApplicationGroup %{GLOBAL}
   
    WSGIScriptAlias / /var/www/site1/FlaskApp/flaskapp.wsgi

</VirtualHost>


                                # site2.conf

<VirtualHost *:80>
    ServerName site2.192.168.1.102
    ServerAlias    site2.me
   
    WSGIDaemonProcess site2 python-home=/var/www/site2/FlaskApp/FlaskApp/venv

    WSGIProcessGroup site2
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias / /var/www/site2/FlaskApp/flaskapp.wsgi

</VirtualHost>




    METHOD 2:   Combined into one virtual host , 3 sites at sub URLs    ie:   sites.me/site4   sites.me/site5    sites.me/site6 
   
                                    # sites.conf
                                   
<VirtualHost *:80>
    ServerName sites.192.168.1.102
    ServerAlias    sites.me
   
    WSGIDaemonProcess site4 python-home=/var/www/site4/FlaskApp/FlaskApp/venv
    WSGIDaemonProcess site5 python-home=/var/www/site5/FlaskApp/FlaskApp/venv
    WSGIDaemonProcess site6 python-home=/var/www/site6/FlaskApp/FlaskApp/venv

    WSGIProcessGroup sites
    WSGIApplicationGroup %{GLOBAL}
   
    WSGIScriptAlias /site4 /var/www/site4/FlaskApp/flaskapp.wsgi
    WSGIScriptAlias /site5 /var/www/site5/FlaskApp/flaskapp.wsgi
    WSGIScriptAlias /site6 /var/www/site6/FlaskApp/flaskapp.wsgi

</VirtualHost> 

Graham Dumpleton

unread,
May 16, 2016, 7:34:42 PM5/16/16
to mod...@googlegroups.com
On 13 May 2016, at 4:28 PM, Jaqen Nki <proj...@gmail.com> wrote:

I see how I should probably structure this for multiple sites now.  Since my server has only one IP, like you said I can do either of two methods, separate vhost for each site (prefixed domains, or combined into one (sub domains).  Heres the configs I came up with, I will have to test it with a new project to see if it works: 

                                            VHOST CONFIGURATION - MULTIPLE SITES                                                    
                                                
        # wsgi.load
        
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so
WSGIRestrictEmbedded On
                                        
                                                
    METHOD 1:    Separate virtual host per project  -  site1  site2                                              
                                
                                # site1.conf

<VirtualHost *:80>
    ServerName site1.192.168.1.102

This doesn’t look right. The value to ServerName should be a fully qualified domain name. You wouldn’t have IP address components in it.
This is referencing an unknown daemon process group.

    WSGIApplicationGroup %{GLOBAL}
    
    WSGIScriptAlias /site4 /var/www/site4/FlaskApp/flaskapp.wsgi

Easiest is to add as extra process-group option to WSGIScriptAlias.

WSGIScriptAlias /site4 /var/www/site4/FlaskApp/flaskapp.wsgi process-group=site4

Jaqen Nki

unread,
Sep 21, 2016, 1:57:57 AM9/21/16
to modwsgi
Hey Graham, been awhile.  Glad I could help ya out with that amzn gift.  Got busy doing other crap and on road trips this summer so took a break from programming.  Also hit a wall with flask where it became difficult to build a dynamic user dashboard system so got discouraged.  I like flask but Im finding its extensibility and total freedom to craft your own web app to be a double edged sword.  I may use it for simple static sites but for more complexity I may have to abandon it because it feels like the things I want to do become too convoluted and require skill on the level of a web/software engineer.  Not sure why I would reinvent the proverbial 'wheel' when at my level it will be inferior and may be bottlenecked or have security breaches Im unaware of when someone at a much higher level has built something much better.  Not only that, to manually edit every sql query, every init.py change, every html change is going to be a logistical nightmare if Im managing like 20 websites.  So Im knocking out a good django series and I like how its structured, more split up, easier to manage via admin panel, apps can be reused etc.  I hope its going to solve some of these logistical and efficiency issues as far as building and managing websites.  My short term goal is to build sites like a blog with commenting system, a forum, dynamic user dashboard, and later on a basic ecommerce store, and to be able to manage these sites easier via django admin (or partially hand the reins to the site owner for basic content posting/editing).   That way my time is freed up from doing menial edits and whatnot for client's sites.  I hope django can be my answer to these dilemmas.

Anyways I was curious if you have experience / advice in this area, and currently Im revisiting how to properly set up numerous projects each with their own separate virtual environment, as we previously discussed below.  I plan on using this local ubuntu VM as my local dev server, hosting all my projects (5-10 short term, 20-50+ eventually) and then uploading them to digital ocean for production.  All I need at the moment is to set up a few projects and make sure their virtualenvs are separate but sharing the same IP.  Thanks.


**********
**********

Graham Dumpleton

unread,
Sep 21, 2016, 10:06:05 PM9/21/16
to mod...@googlegroups.com
If the intention is still to try and do it yourself with one Apache instance, the description given before is still valid.

So not sure I have anything more to add at this point. Personally I am a fan of PaaS, but cost can be a concern with those.

Can perhaps go more into it when you start progressing more with the setup.

Graham 

Jaqen Nki

unread,
Sep 23, 2016, 3:46:56 AM9/23/16
to modwsgi
Ok, so I followed the steps above, and lo and behold the site1.me worked!  But my 2nd test site at site2.me did not.  (What I did was duplicate my site1 project as site2, changed all the conf files and gave it a new database to reflect the change.  I think theres some conflict as both vhost configs are trying to share the same local IP.  I noticed in the vhost file the ServerName has an incorrect IP address (192.168.1.7) for the ubuntu server but it doesnt affect anything since the ServerAlias site1.me points to the correct server IP on my mac's /etc/hosts file:  192.168.1.11   site1.me.)  I got this info upon visiting that domain :

(0)REMOTE_ADDR = 206.127.117.221
REMOTE_PORT = 11233
HTTP_USER_AGENT = Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_CHARSET =
HTTP_CONNECTION = keep-alive
HTTP_HOST = site2.me
HTTP_REFERER =
REQUEST_METHOD = GET
GATEWAY_INTERFACE = CGI/1.1
PATH_TRANSLATED =
SERVER_NAME = site2.me
SERVER_ADDR = 192.168.5.5
2016-09-23 10:29:04

After which I tested copying the same line in /etc/hosts on mac,
192.168.1.11 site1.me
192.168.1.11 site2.me
and when visiting site2.me in browser I actually got the Apache2 Ubuntu Default - It Works! page, so Im close but theres some conflict with an IP or hostname it seems. 

Graham Dumpleton

unread,
Sep 23, 2016, 5:28:01 AM9/23/16
to mod...@googlegroups.com
Can you post the two VirtualHost configurations?

The IP address should not be mentioned in the VirtualHost definition anywhere normally. So shouldn’t have IP in ServerName either.

Graham

Jaqen Nki

unread,
Sep 23, 2016, 7:07:19 AM9/23/16
to modwsgi
yeah my bad:

<VirtualHost *:80>
                ServerName 192.168.1.10
                ServerAlias site1.me
                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site1 python-home=/var/www/site1/FlaskApp/FlaskApp/venv

                WSGIProcessGroup site1
                WSGIApplicationGroup %{GLOBAL}
                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 /var/www/site1/logs/error.log
                LogLevel warn
                CustomLog /var/www/site1/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
                ServerName 192.168.1.10
                ServerAlias site2.me
                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site1 python-home=/var/www/site2/FlaskApp/FlaskApp/venv

                WSGIProcessGroup site2
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/site2/FlaskApp/flaskapp.wsgi
                <Directory /var/www/site2/FlaskApp/FlaskApp/>

                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/site2/FlaskApp/FlaskApp/static
                <Directory /var/www/site2/FlaskApp/FlaskApp/static/>

                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog /var/www/site2/logs/error.log
                LogLevel warn
                CustomLog /var/www/site2/logs/access.log combined
</VirtualHost>
Message has been deleted

Graham Dumpleton

unread,
Sep 23, 2016, 7:11:24 AM9/23/16
to mod...@googlegroups.com
On 23 Sep 2016, at 9:07 PM, Jaqen Nki <proj...@gmail.com> wrote:

yeah my bad:

<VirtualHost *:80>
                ServerName 192.168.1.10
                ServerAlias site1.me

Only use:

ServerName site1.me

Don’t use ServerAlias and don’t use the IP.

                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site1 python-home=/var/www/site1/FlaskApp/FlaskApp/venv
                WSGIProcessGroup site1
                WSGIApplicationGroup %{GLOBAL}
                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 /var/www/site1/logs/error.log
                LogLevel warn
                CustomLog /var/www/site1/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
                ServerName 192.168.1.10
                ServerAlias site2.me

ServerName site2.me

                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site1 python-home=/var/www/site2/FlaskApp/FlaskApp/venv

This should be:

     WSGIDaemonProcess site2 python-home=/var/www/site2/FlaskApp/FlaskApp/venv

The server shouldn’t even have started with what you had as site1 name already used and should have complained about duplicate. Are you sure both were being read.

Also, do you actually have resolvable DNS for site1.me and site2.me, or entries for them in /etc/hosts. Name based virtual hosts will not work without.

Graham

Jaqen Nki

unread,
Sep 23, 2016, 7:33:51 AM9/23/16
to modwsgi
Hmm I had the DaemonProcess correct just not in the above post, and I changed the ServerName to site1.me and site2.me, the etc/hosts file has them both at 192.168.1.10.  Not sure if/how to resolve the DNS figured that was automatic.  My network settings say using DHCP, and I use openDNS.  Would I have to add other DNS entries for each vhost?

Graham Dumpleton

unread,
Sep 23, 2016, 7:40:07 AM9/23/16
to mod...@googlegroups.com
If you have it with ServerName as I suggest, and there ate /etc/hosts entries mapping the host names to the local system IP, then using:


should result in them going to the correct VirtualHost and being handled by respective applications.

If they aren’t it would suggest the VirtualHost’s aren’t being read by Apache.

What file are they in?

If you put a syntax error in the VirtualHost definitions, does Apache fail to start.

Just add a line with:

   xxxx

and it should fail.

Graham

Jaqen Nki

unread,
Sep 23, 2016, 8:02:22 AM9/23/16
to modwsgi
Heres

/etc/apache2/sites-available$ ls
000-default.conf  default-ssl.conf  site1.conf  site2.conf


config files:

etchost:

##
# 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.10    site1.me        http://site1.me
192.168.1.10    site2.me        http://site2.me



<VirtualHost *:80>
                ServerName http://site1.me

                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site1 python-home=/var/www/site1/FlaskApp/FlaskApp/venv
                WSGIProcessGroup site1
                WSGIApplicationGroup %{GLOBAL}
                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 /var/www/site1/logs/error.log
                LogLevel warn
                CustomLog /var/www/site1/logs/access.log combined
</VirtualHost>


<VirtualHost *:80>
                ServerName http://site2.me
                ServerAdmin ad...@mywebsite.com

                WSGIDaemonProcess site2 python-home=/var/www/site2/FlaskApp/FlaskApp/venv

                WSGIProcessGroup site2
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/site2/FlaskApp/flaskapp.wsgi
                <Directory /var/www/site2/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/site2/FlaskApp/FlaskApp/static
                <Directory /var/www/site2/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog /var/www/site2/logs/error.log
                LogLevel warn
                CustomLog /var/www/site2/logs/access.log combined
</VirtualHost>


cat /etc/apache2/mods-available/wsgi.load


LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so
WSGIRestrictEmbedded On

Im now getting 500 error at site2.me.  site1 still works.

Graham Dumpleton

unread,
Sep 23, 2016, 8:09:54 AM9/23/16
to mod...@googlegroups.com
I meant to use:


in the browser when making the request, not in ServerName. ServerName should be just the hostname.

Are their symlinks in the sites-enabled directory to the files in the sites-available directory?

Just because they are in sites-available doesn’t mean Apache will read them. On your Linux distro the sites have to be enabled, using s2enable, which results in a symlink being put in sites-enabled to same site in sites-available.

Graham

Jaqen Nki

unread,
Sep 24, 2016, 2:27:34 AM9/24/16
to modwsgi
Gotcha.  I fixed those to be site.1me and site2.me only in ServerName fields.  Also after making a new vhost file I run

sudo a2ensite site2.

It appears the configuration is working, though I have a new problem.  After checking apache error log for 500 on site2.me, it says exception, cant import pygal etc.  So I think, thats easy fix, I turn on the venv, go pip3 install pygal.  Apparently pip3 cant install stuff now in the venv, or requirements.txt   Ill post error below, sorry for its length. 


(venv) kien1@k1pvm:/var/www/site2/FlaskApp/FlaskApp$ pip3 install -r requirements.txt
Collecting blinker==1.4 (from -r requirements.txt (line 1))
Exception:
Traceback (most recent call last):
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 137, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/connection.py", line 67, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 787, in _validate_conn
    conn.connect()
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 217, in connect
    conn = self._new_conn()
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 146, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f65a396e470>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/lib/python3.5/site-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/var/www/site2/FlaskApp/FlaskApp/venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
I meant to use:

To post to this group, send email to mod...@googlegroups.com<span style="font-family: Helvetica; font-

Jaqen Nki

unread,
Sep 24, 2016, 2:55:12 AM9/24/16
to modwsgi
I think you were right, now Im running into DNS resolution issues with pip venvs.  Heres two links I did digging on. 

https://wiki.archlinux.org/index.php/Resolv.conf

The method I tried was:

Modify the dhcpcd config

Alternatively, you can create a file called /etc/resolv.conf.head containing your DNS servers. dhcpcd will prepend this file to the beginning of /etc/resolv.conf.


sudo nano /etc/resolv.conf.head


# OpenDNS IPv4 nameservers
nameserver 208.67.222.222
nameserver 208.67.220.220


https://gregalbrecht.com/2010/04/22/python-macos/                        this link may be of some relevance.




Jaqen Nki

unread,
Sep 24, 2016, 3:17:37 AM9/24/16
to modwsgi
I suppose I should have mentioned, I set up ubuntu vm to use a static IP, since it changes like every time I fire up the server. which gets really annoying.  

EDIT:   OMG just got site2.me working !  Im a genius (in theory).  In addition to the /etc/resolv/conf.head I added the dns-nameservers line to /etc/network/interfaces file :

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto enp0s5
iface enp0s5 inet static
address 192.168.1.20
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 208.67.222.222 208.67.220.220


Sweet.  Now Im going to do a little more work, setting up a few flask projects.  Then I need to do the same thing and set up django projects with their own vhosts.  I think the process is similar but with slight differences with django.  Anyways Ill be done buggin ya for now.  Thanks for pointing me in the right direction, dns resolution yikes.

Jaqen Nki

unread,
Sep 26, 2016, 2:11:29 AM9/26/16
to modwsgi
Sweet so I got a django app configured to serve properly with mod wsgi.  A slight difference in wsgidaemonprocess from the flask config.  Now I can do all my projects locally and in one place. 

<VirtualHost *:80>
                ServerName dsite1.me

                WSGIDaemonProcess dsite1 python-path=/var/www/dtuts/dsite1:/var/www/dtuts/dsite1/venv/lib/python3.5/site-packages
                WSGIProcessGroup dsite1
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/dtuts/dsite1/dsite1/wsgi.py
                <Directory /var/www/dtuts/dsite1/>
                #<Files wsgi.py>

                        Order allow,deny
                        Allow from all
                #</Files>
                </Directory>

                #Alias /robots.txt /path/to/mysite.com/static/robots.txt
                #Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

                #Alias /media /var/www/dtuts/dsite1/media
                #<Directory /path/to/mysite.com/media>
                 #       Order allow,deny
                 #       Allow from all
                #</Directory>

               # Alias /static /var/www/dtuts/dsite1/static
                #<Directory /var/www/dtuts/dsite1/static/>
                 #       Order allow,deny
                 #       Allow from all
                #</Directory>
                ErrorLog /var/www/dtuts/dsite1/logs/error.log
                LogLevel warn
                CustomLog /var/www/dtuts/dsite1/logs/access.log combined
</VirtualHost>


Now comes the hard part of building quality full featured apps, integrating dashboard, forums, cms, ecommerce, comment system, etc and managing them in the least painful way.  Feels like climbing an insurmountable mountain, with each step consisting of about 10 convoluted rabbit holes, and each of those splitting into 10 more.  My main issue is learning how to learn to write code, learning the abstraction layers of python and being able to engineer apps on my own, as well as motivation/perseverance in the face of discouragement.  I guess Ill just have to delve deep on the net for solutions and try and find a mentor willing to help show me how to construct high end apps so I can market them and make some good money doing so hopefully.  Anyways if you have any counsel regarding this that would be great, otherwise thanks again so much for the help.  Catch ya later.

Graham Dumpleton

unread,
Sep 26, 2016, 2:18:49 AM9/26/16
to mod...@googlegroups.com
On 26 Sep 2016, at 4:11 PM, Jaqen Nki <proj...@gmail.com> wrote:

Sweet so I got a django app configured to serve properly with mod wsgi.  A slight difference in wsgidaemonprocess from the flask config.  Now I can do all my projects locally and in one place. 

<VirtualHost *:80>
                ServerName dsite1.me

                WSGIDaemonProcess dsite1 python-path=/var/www/dtuts/dsite1:/var/www/dtuts/dsite1/venv/lib/python3.5/site-packages

Instead of this use:

    WSGIDaemonProcess dsite1 python-home=/var/www/dtuts/dsite1/venv python-path=/var/www/dtuts/dsite1

That is, use python-home option for location of the virtual environment. The location is what sys.prefix in the interpreter yields for that virtual environment.

                WSGIProcessGroup dsite1
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/dtuts/dsite1/dsite1/wsgi.py
                <Directory /var/www/dtuts/dsite1/>
                #<Files wsgi.py>

You are better have Files section here uncommented and is only the wsgi.py that Apache needs to be told it is allowed to serve. More secure than what you have.

Graham

                        Order allow,deny
                        Allow from all
                #</Files>
                </Directory>

                #Alias /robots.txt /path/to/mysite.com/static/robots.txt
                #Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

                #Alias /media /var/www/dtuts/dsite1/media
                #<Directory /path/to/mysite.com/media>
                 #       Order allow,deny
                 #       Allow from all
                #</Directory>

               # Alias /static /var/www/dtuts/dsite1/static
                #<Directory /var/www/dtuts/dsite1/static/>
                 #       Order allow,deny
                 #       Allow from all
                #</Directory>
                ErrorLog /var/www/dtuts/dsite1/logs/error.log
                LogLevel warn
                CustomLog /var/www/dtuts/dsite1/logs/access.log combined
</VirtualHost>


Now comes the hard part of building quality full featured apps, integrating dashboard, forums, cms, ecommerce, comment system, etc and managing them in the least painful way.  Feels like climbing an insurmountable mountain, with each step consisting of about 10 convoluted rabbit holes, and each of those splitting into 10 more.  My main issue is learning how to learn to write code, learning the abstraction layers of python and being able to engineer apps on my own, as well as motivation/perseverance in the face of discouragement.  I guess Ill just have to delve deep on the net for solutions and try and find a mentor willing to help show me how to construct high end apps so I can market them and make some good money doing so hopefully.  Anyways if you have any counsel regarding this that would be great, otherwise thanks again so much for the help.  Catch ya later.

Jaqen Nki

unread,
Sep 26, 2016, 4:05:37 AM9/26/16
to modwsgi
Got it, good to know.  Can confirm it is indeed working.  Thanks m8

Jaqen Nki

unread,
Nov 11, 2016, 1:12:40 AM11/11/16
to modwsgi
Hey graham, have a quick issue.

tested out flaskbb forums, with the docs command runserver I can get it to run on localhost 8080, but Im trying to set it up to run like all my other virtualhosts, permanently at forum1.me.  The guys at flaskbb admit they havent tried apache wsgi config, but I dont see why it shouldnt, as the wsgi.py looks similar to django config.   Heres the vhost config, wsgi.py and apache errors. 

# vhost  forum1.conf

<VirtualHost *:80>
                ServerName forum1.me

                WSGIDaemonProcess forum1 python-home=/var/www/forum1/flaskbb-master/venv
                WSGIProcessGroup forum1
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/forum1/flaskbb-master/wsgi.py
                <Directory /var/www/forum1/flaskbb-master/>

                       Order allow,deny
                       Allow from all
                </Directory>
                Alias /static /var/www/forum1/flaskbb-master/flaskbb/static
                <Directory /var/www/forum1/flaskbb-master/flaskbb/static/>

                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog /var/www/forum1/logs/error.log
                LogLevel warn
                CustomLog /var/www/forum1/logs/access.log combined
</VirtualHost>



# wsgi.py            

from flaskbb import create_app
from flaskbb.configs.production import ProductionConfig

flaskbb = create_app(config=ProductionConfig())



# First apache error :

ImportError: No module named 'flaskbb'
[Thu Nov 10 22:36:41.807983 2016] [wsgi:error] [pid 29935:tid 139908161734400] [remote 192.168.1.6:51168] mod_wsgi (pid=29935): Target WSGI script '/var/www/forum1/flaskbb-master/wsgi.py' cannot be loaded as Python module.


# 2nd error,  after trying relative imports:

from .flaskbb import create_app
[Thu Nov 10 22:53:23.638380 2016] [wsgi:error] [pid 1153:tid 139996606498560] [remote 192.168.1.6:32637] SystemError: Parent module '' not loaded, cannot perform relative import
[Thu Nov 10 22:53:24.827499 2016] [wsgi:error] [pid 1153:tid 139996690425600] [remote 192.168.1.6:32637] mod_wsgi (pid=1153): Target WSGI script '/var/www/forum1/flaskbb-master/wsgi.py' cannot be loaded as Python module.




Graham Dumpleton

unread,
Nov 11, 2016, 1:17:57 AM11/11/16
to mod...@googlegroups.com
On 11 Nov 2016, at 5:12 PM, Jaqen Nki <proj...@gmail.com> wrote:

Hey graham, have a quick issue.

tested out flaskbb forums, with the docs command runserver I can get it to run on localhost 8080, but Im trying to set it up to run like all my other virtualhosts, permanently at forum1.me.  The guys at flaskbb admit they havent tried apache wsgi config, but I dont see why it shouldnt, as the wsgi.py looks similar to django config.   Heres the vhost config, wsgi.py and apache errors. 

# vhost  forum1.conf

<VirtualHost *:80>
                ServerName forum1.me

                WSGIDaemonProcess forum1 python-home=/var/www/forum1/flaskbb-master/venv

Add additional option:

    python-path=/var/www/forum1/flaskbb-master

Make sure you leave python-home there.

If ‘flaskbb’ application package is under '/var/www/forum1/flaskbb-master’ that is why it cannot be found.

                WSGIProcessGroup forum1
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptAlias / /var/www/forum1/flaskbb-master/wsgi.py
                <Directory /var/www/forum1/flaskbb-master/>
                       Order allow,deny
                       Allow from all
                </Directory>
                Alias /static /var/www/forum1/flaskbb-master/flaskbb/static
                <Directory /var/www/forum1/flaskbb-master/flaskbb/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog /var/www/forum1/logs/error.log
                LogLevel warn
                CustomLog /var/www/forum1/logs/access.log combined
</VirtualHost>



# wsgi.py            

from flaskbb import create_app
from flaskbb.configs.production import ProductionConfig

flaskbb = create_app(config=ProductionConfig())


You need to change this to use:

    application = create_app(config=ProductionConfig())

as mod_wsgi by default expects the WSGI application entry point to be called ‘application’. What is returned by create_app() does need to be a WSGI application callable though. If it isn’t, then will not work.

Graham

# First apache error :

ImportError: No module named 'flaskbb'
[Thu Nov 10 22:36:41.807983 2016] [wsgi:error] [pid 29935:tid 139908161734400] [remote 192.168.1.6:51168] mod_wsgi (pid=29935): Target WSGI script '/var/www/forum1/flaskbb-master/wsgi.py' cannot be loaded as Python module.


# 2nd error,  after trying relative imports:

from .flaskbb import create_app
[Thu Nov 10 22:53:23.638380 2016] [wsgi:error] [pid 1153:tid 139996606498560] [remote 192.168.1.6:32637] SystemError: Parent module '' not loaded, cannot perform relative import
[Thu Nov 10 22:53:24.827499 2016] [wsgi:error] [pid 1153:tid 139996690425600] [remote 192.168.1.6:32637] mod_wsgi (pid=1153): Target WSGI script '/var/www/forum1/flaskbb-master/wsgi.py' cannot be loaded as Python module.





Jaqen Nki

unread,
Nov 11, 2016, 1:33:05 AM11/11/16
to modwsgi
OMG you nailed it.  works 100%.  kickass man thanks so much for your expertise.  now Im going to delve into figuring out this forum, one more app I can use in my web development service.  cheers catch ya later.

Jaqen Nki

unread,
Dec 1, 2016, 2:05:21 AM12/1/16
to modwsgi
Hey, have a small problem.  Today was messing around trying to add a multiple image upload integration in django admin panel.  Couldnt get it working.  Beforehand I duplicated the whole project folder, as a backup.  Then I deleted the modified one, renamed the backup as dtuts and tried to run things as normal and the app is broken. deleted cached files and deleted the venv, recreated venv and install django and ckeditor inside it.  Still broken.  Thought I could be able to copy paste a duplicate backup in case things went wrong.  Boy was I wrong,  What a fking mess.  Heres the apache log:

[Thu Dec 01 06:59:53.278214 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418] mod_wsgi (pid=27439): Target WSGI script '/var/www/dtuts/dsite1/dsite1/wsgi.py' cannot be loaded as Python module.
[Thu Dec 01 06:59:53.278308 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418] mod_wsgi (pid=27439): Exception occurred processing WSGI script '/var/www/dtuts/dsite1/dsite1/wsgi.py'.
[Thu Dec 01 06:59:53.279167 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418] Traceback (most recent call last):
[Thu Dec 01 06:59:53.279219 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/dsite1/dsite1/wsgi.py", line 16, in <module>
[Thu Dec 01 06:59:53.279224 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     application = get_wsgi_application()
[Thu Dec 01 06:59:53.279231 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Dec 01 06:59:53.279234 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     django.setup(set_prefix=False)
[Thu Dec 01 06:59:53.279239 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
[Thu Dec 01 06:59:53.279242 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     apps.populate(settings.INSTALLED_APPS)
[Thu Dec 01 06:59:53.279247 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
[Thu Dec 01 06:59:53.279250 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     app_config.import_models(all_models)
[Thu Dec 01 06:59:53.279255 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/apps/config.py", line 199, in import_models
[Thu Dec 01 06:59:53.279257 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     self.models_module = import_module(models_module_name)
[Thu Dec 01 06:59:53.279263 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Dec 01 06:59:53.279266 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     return _bootstrap._gcd_import(name[level:], package, level)
[Thu Dec 01 06:59:53.279270 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Dec 01 06:59:53.279276 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Dec 01 06:59:53.279281 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
[Thu Dec 01 06:59:53.279286 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[Thu Dec 01 06:59:53.279291 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap_external>", line 661, in exec_module
[Thu Dec 01 06:59:53.279296 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap_external>", line 767, in get_code
[Thu Dec 01 06:59:53.279302 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap_external>", line 727, in source_to_code
[Thu Dec 01 06:59:53.279307 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Dec 01 06:59:53.279332 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]   File "/var/www/dtuts/dsite1/blog/models.py", line 7
[Thu Dec 01 06:59:53.279341 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]     title = models.CharField(max_length = 140)
[Thu Dec 01 06:59:53.279367 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418]                                              ^
[Thu Dec 01 06:59:53.279376 2016] [wsgi:error] [pid 27439:tid 140254376425216] [remote 192.168.1.6:33418] IndentationError: unindent does not match any outer indentation level

Graham Dumpleton

unread,
Dec 1, 2016, 2:08:27 AM12/1/16
to mod...@googlegroups.com
The error indicates the indenting in your code file /var/www/dtuts/dsite1/blog/models.py is messed up.

Check your indenting. Make sure indenting all uses spaces and not a mix of spaces and tabs. You can have problems if using both spaces and tabs and your tab width is set to something strange in your editor such that looks like it lines up but doesn’t.

Graham

Jaqen Nki

unread,
Dec 1, 2016, 2:13:52 AM12/1/16
to modwsgi
You are right, coda2 editor somehow screws up python code indentation.  Fixed that.  now getting this in django debugger in browser:

DisallowedHost at /

Invalid HTTP_HOST header: 'dsite1.me'. You may need to add 'dsite1.me' to ALLOWED_HOSTS.


Traceback:

File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/utils/deprecation.py" in __call__
  134.             response = self.process_request(request)

File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/middleware/common.py" in process_request
  57.         host = request.get_host()

File "/var/www/dtuts/venv/lib/python3.5/site-packages/django/http/request.py" in get_host
  113.             raise DisallowedHost(msg)

Exception Type: DisallowedHost at /
Exception Value: Invalid HTTP_HOST header: 'dsite1.me'. You may need to add 'dsite1.me' to ALLOWED_HOSTS.

Graham Dumpleton

unread,
Dec 1, 2016, 2:16:20 AM12/1/16
to mod...@googlegroups.com
As the error indicates, you need to modify the Django settings module and set ALLOWED_HOSTS settings appropriately.

It is suggesting you set it to:

    ALLOWED_HOSTS = [‘dsite1.me’]

corresponding to the names of the sites your Django site is hosting for.

If unsure, set it to:

    ALLOWED_HOSTS = [‘*’]

Ensure those are all single quotes. Stupid email program is turning them into fancy balanced quotes.

Graham

Jaqen Nki

unread,
Dec 1, 2016, 2:16:25 AM12/1/16
to modwsgi
added dsite1.me  to ALLOWED_HOSTS = []

not sure why Id need that though, didnt have it before...   still error:


[Thu Dec 01 00:17:04.234666 2016] [wsgi:error] [pid 31133:tid 140044190902016] [remote 192.168.1.6:49299]     ALLOWED_HOSTS = [dsite1.me]
[Thu Dec 01 00:17:04.234679 2016] [wsgi:error] [pid 31133:tid 140044190902016] [remote 192.168.1.6:49299] NameError: name 'dsite1' is not defined

Jaqen Nki

unread,
Dec 1, 2016, 2:20:21 AM12/1/16
to modwsgi
nevermind got it, needed single quotes as you said.   thanks for the rescue lol.

Graham Dumpleton

unread,
Dec 1, 2016, 2:25:42 AM12/1/16
to mod...@googlegroups.com
It wasn’t in older Django versions if you had upgraded. It also doesn’t need to be set if you have Django DEBUG mode enabled. Also only needed with real WSGI servers and not the Django development server.

Graham

Jaqen Nki

unread,
Dec 14, 2016, 8:56:05 PM12/14/16
to modwsgi
hey quick question, how would i configure a site to run on loopback, sometimes when traveling dont have wifi 100% of time and would like to still be able to develop.  would i change my static ip config on ubuntu?  which currently looks like this:

# /etc/networking/interfaces


# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto enp0s5
iface enp0s5 inet static
address 10.231.208.199
netmask 255.255.255.0
gateway 10.128.128.128
network 10.128.128.0
broadcast 10.128.128.255

# OpenDNS IPv4 nameservers
dns-nameservers 10.128.128.128

# OpenDNS IPv6 nameservers
#dns-nameservers 2620:0:ccc::2 2620:0:ccd::2


or could i clone a site to run on loopback, and add a separate config for that in this same file, so i could access them both while connected and offline?
lastly how would i point my macs /etc/hosts file to serve the ubuntu servers localhost?



Graham Dumpleton

unread,
Dec 14, 2016, 9:03:31 PM12/14/16
to mod...@googlegroups.com
Am somewhat confused about the question being asked.

Are you talking about the Apache/mod_wsgi site you had issues with setting up before?

You mention both Ubuntu servers and a Mac, so not really sure what you are asking and how things hang together.

For local development you are possibly better off not using the main operating system Apache setup, but use mod_wsgi-express instead. You can run up your application on a non privileged port from the command line and access it via localhost.

See:


Graham

Jaqen Nki

unread,
Dec 14, 2016, 9:11:51 PM12/14/16
to modwsgi
yeah i meant using the ubuntu server as normal to serve the website to my mac locally, so its still behaving as a real website, without the net though.   as now my apache server is configured to serve multiple sites with multiple vhosts.  each one has its own domain.  site1.me is my main project.  id like to make site0.me a clone of site1.me thats served to my mac locally.

/etc/hosts on mac:


##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost


10.231.208.199  site1.me        http://site1.me
192.168.1.20     flask0.me      http://flask0.me
192.168.1.20     dsite1.me      http://dsite1.me
192.168.1.20    forum1.me       http://forum1.me


so could i set up a vhost for site0.me and give it an ip  like

127.0.0.1  site0.me http://site0.me

Graham Dumpleton

unread,
Dec 14, 2016, 9:18:52 PM12/14/16
to mod...@googlegroups.com
But if the site runs on an Ubuntu server, doesn’t that mean it is remote to your Mac, and if you have no WiFi, how can you then communicate with it? This is why the question was confusing.

On 15 Dec 2016, at 1:11 PM, Jaqen Nki <proj...@gmail.com> wrote:

yeah i meant using the ubuntu server as normal to serve the website to my mac locally, so its still behaving as a real website, without the net though.   as now my apache server is configured to serve multiple sites with multiple vhosts.  each one has its own domain.  site1.me is my main project.  id like to make site0.me a clone of site1.me thats served to my mac locally.

/etc/hosts on mac:

##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost


10.231.208.199  site1.me        http://site1.me
192.168.1.20     flask0.me      http://flask0.me
192.168.1.20     dsite1.me      http://dsite1.me
192.168.1.20    forum1.me       http://forum1.me

You can't have a URL in your /etc/hosts file like that.

so could i set up a vhost for site0.me and give it an ip  like 

Only thing I can think to tell you is that when you have a VirtualHost, it needs to have the ServerName directive set within the VirtualHost. It is this which dictates that that VirtualHost is applied when a request is received for that host name.

In other words, Apache doesn’t care what the IP address was.

You could therefore override DNS by adding an manual entry in your /etc/hosts file which mapped:

    127.0.0.1 site1.me

So you don’t even need to use a separate host name.

If you did still want to have a separate host name, then in addition to ServerName in the VirtualHost, add:

    ServerAlias site0.me

Then in the /etc/hosts file add:

    127.0.0.1 site0.me

So you are leaving site1.me alone, but allowing site0.me as an alias for accessing the same site.

Graham

Message has been deleted
Message has been deleted

Graham Dumpleton

unread,
Dec 14, 2016, 9:54:15 PM12/14/16
to mod...@googlegroups.com

On 15 Dec 2016, at 1:46 PM, Jaqen Nki <proj...@gmail.com> wrote:

sorry yea let me clarify, i realized with no net my mac wont be able to comm with the ubuntu server.  so the easiest option for offline work is to operate on the ubuntu vm itself.  I activated venv in site1, ran

mod_wsgi-express start-server

and it shows the malt whiskey test page on localhost:8000. forgive me but how do i target the flask application in /var/www/site1/FlaskApp/FlaskApp to be able to serve that website running the script?


There are examples in the PyPi documentation, but at a guess based on the Flask site you described the configuration of previously:

    cd /var/www/forum1/flaskbb-master
    source venv/bin/activate

    mod_wsgi-express start-server --url-alias /static flaskbb/static wsgi.py

Also see posts about mod_wsgi-express on my blog.


Graham

On Wednesday, December 14, 2016 at 7:18:53 PM UTC-7, Jaqen Nki wrote:
although i foresee this not working, because if offline my ubuntu VM bridge network adapter doesnt work properly without internet.  maybe you are right, better off running a modwsgi express start from within the activated venv.  could i do this without disturbing any current configs?

Jaqen Nki

unread,
Dec 14, 2016, 9:55:01 PM12/14/16
to modwsgi
ok never mind I got it.  ran

mod_wsgi-express start-server flaskapp.wsgi 

and it serves at localhost:8000 on ubuntu vm. much simpler temporary solution than doing a bunch of configuration monkey shit. thanks sorry to bug, this is exactly what I was looking for. .


Message has been deleted
Message has been deleted
Message has been deleted

Jaqen Nki

unread,
Dec 25, 2016, 9:21:48 PM12/25/16
to modwsgi
hey bro just wanna say happy holidays.  my initial launch is up, at skylinedev.net.  still got a good amount of work to do but it looks pretty good for my first site.  all setup as a legal small business.  anways, when youre free this week, just have another task, basically to set up SSL for my site.  I though lets encrypt might work but i found out too late it only supports python 2x. Saw a post where you mentioned using ssl with mod wsgi and apache2 and its relatively simple.  looking forward to it.  catch ya later. cheers.

Graham Dumpleton

unread,
Dec 28, 2016, 10:58:03 PM12/28/16
to mod...@googlegroups.com

On 26 Dec 2016, at 1:21 PM, Jaqen Nki <proj...@gmail.com> wrote:

hey bro just wanna say happy holidays.  my initial launch is up, at skylinedev.net.  still got a good amount of work to do but it looks pretty good for my first site.  all setup as a legal small business.  anways, when youre free this week, just have another task, basically to set up SSL for my site.  I though lets encrypt might work but i found out too late it only supports python 2x. Saw a post where you mentioned using ssl with mod wsgi and apache2 and its relatively simple.  looking forward to it.  catch ya later. cheers.

Getting a certificate using lets encrypt is an entirely separate process to configuring Apache to use the certificate. So it doesn’t matter that it is Python 2. Get you SSL certificate sorted out first using the lets encrypt tools manually, and then configure Apache to use it.


Graham

Jaqen Nki

unread,
Dec 30, 2016, 3:19:41 AM12/30/16
to modwsgi
Ok got it.  I will work on that.  Quick question as well, im trying to redirect www.skylinedev.net to http://skylinedev.net.  tried adding this top part to my vhost but not working:

<VirtualHost *:80>
    ServerName www.skylinedev.net
    Redirect permanent / http://skylinedev.net
</VirtualHost>

# original vhost
<VirtualHost *:80>
    ServerName http://skylinedev.net
    full server info etc...
   
</VirtualHost>

Graham Dumpleton

unread,
Dec 30, 2016, 3:26:29 AM12/30/16
to mod...@googlegroups.com
On 30 Dec 2016, at 7:19 PM, Jaqen Nki <proj...@gmail.com> wrote:

Ok got it.  I will work on that.  Quick question as well, im trying to redirect www.skylinedev.net to http://skylinedev.net.  tried adding this top part to my vhost but not working:

<VirtualHost *:80>
    ServerName www.skylinedev.net
    Redirect permanent / http://skylinedev.net
</VirtualHost>

# original vhost
<VirtualHost *:80>
    ServerName http://skylinedev.net

This should not be a URL, but just:


The other way of doing it is to have one VirtualHost with ServerName skylinedev.net which has a ServerAlias of www.skylinedev.net and use mod_rewrite rules to match when hostname is later and redirect in that case using rewrite rules.

BTW, there are technical reasons why it is better to have ‘www’ be the primary name and redirect the other way. Read:


Graham

    full server info etc...
    
</VirtualHost>

On Wednesday, December 28, 2016 at 8:58:03 PM UTC-7, Graham Dumpleton wrote:

On 26 Dec 2016, at 1:21 PM, Jaqen Nki <proj...@gmail.com> wrote:

hey bro just wanna say happy holidays.  my initial launch is up, at skylinedev.net.  still got a good amount of work to do but it looks pretty good for my first site.  all setup as a legal small business.  anways, when youre free this week, just have another task, basically to set up SSL for my site.  I though lets encrypt might work but i found out too late it only supports python 2x. Saw a post where you mentioned using ssl with mod wsgi and apache2 and its relatively simple.  looking forward to it.  catch ya later. cheers.

Getting a certificate using lets encrypt is an entirely separate process to configuring Apache to use the certificate. So it doesn’t matter that it is Python 2. Get you SSL certificate sorted out first using the lets encrypt tools manually, and then configure Apache to use it.


Graham


Jaqen Nki

unread,
Dec 30, 2016, 4:04:30 AM12/30/16
to modwsgi
ok good to know, i would like to have www as default upon learning that info, just not sure how at this point.  i followed guide here https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-apache-on-ubuntu-14-04 (didnt do htaccess and rewrite mod stuff) and redirect still not working.

added A records on digital ocean    for both   @  MYIPADDRESS      and      www MYIPADDRESS

also apache cannot start unless the redirect block has  http:// :    Redirect permanent / http://skylinedev.net    ,  but in the main server config I have just:   ServerName skylinedev.net

error : systemctl status apache2.service 

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Fri 2016-12-30 08:59:48 UTC; 10s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3492 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 32438 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 3522 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

# journalctl -xe

 Dec 30 09:00:39 ubuntu-16-skylinedev sshd[3547]: Failed password for root from 221.194.44.195 port 50166 ssh2
Dec 30 09:00:39 ubuntu-16-skylinedev sshd[3547]: Received disconnect from 221.194.44.195 port 50166:11:  [preauth]
Dec 30 09:00:39 ubuntu-16-skylinedev sshd[3547]: Disconnected from 221.194.44.195 port 50166 [preauth]
It is loading more messages.
0 new messages