--
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.
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/
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>
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
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
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)
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
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
sudo nano /etc/apache2/sites-available/site1.conf
<VirtualHost *:80>
ServerName 192.168.1.102
ServerAlias site1.me
ServerAdmin ad...@mywebsite.com
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.
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 site2ServerName site1.192.168.1.102
# site1.conf
<VirtualHost *:80>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias /site4 /var/www/site4/FlaskApp/flaskapp.wsgi
On 23 Sep 2016, at 9:07 PM, Jaqen Nki <proj...@gmail.com> wrote:
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
I meant to use:
To post to this group, send email to mod...@googlegroups.com<span style="font-family: Helvetica; font-
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
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
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.
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
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.
Invalid HTTP_HOST header: 'dsite1.me'. You may need to add 'dsite1.me' to ALLOWED_HOSTS.
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
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, ranmod_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?
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?
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. .
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.
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
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