so here's the setting:
The whole site is working fine if I remove the application (whose name
is myapp) in the INSTALLED_APPS section in the settings file I added WSGIPythonHome in apache2.conf
I can successfully access the apps via the the interactive python shell in Django (python manage.py shell). I can create, update and delete data.
I am using the standard Apache 2 setup for Ubuntu 10.04 Lucid Lynx(sites-enabled, mods-enabled, apache2.conf, etc)
I am running a virtualenv located in /home/ygamretuta/dev/myproject
My django project is located in /home/ygamretuta/dev/site1
error Log file says this (last 2 lines):
File "/home/ygamretuta/dev/myproject/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
TemplateSyntaxError: Caught ImportError while rendering: No module named myapp
my django.wsgi contains this:
import os, sys
sys.path.append('/home/ygamretuta/dev')
os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
my virtual host file for site1.com (contained in the sites-available folder) contains this (stripped of other details):
WSGIDaemonProcess ygamretuta processes=2 maximum-requests=500 threads=1
WSGIProcessGroup ygamretuta
WSGIScriptAlias / /home/ygamretuta/dev/site1/apache/django.wsgi
What could I have missed? I am getting e 500 Internal Server Error if the custom apps (the ones I made with manage.py startapp) are not commented out
Append /home/ygamretuta/dev/site1 to sys.path.
Related
Using Red Hat, apache 2.4.6, worker mpm, mod_wsgi 4.6.5, and Python 3.7 When I start httpd I get the above error and:
ModuleNotFoundError: No module named 'encodings'
In the httpd error_log.
I'm using a python virtual environment created from a python installed from source under my home directory. I installed mod_wsgi from source using --with-python= option pointing to the python binary in my virtual environment, then I copied the mod_wsgi.so file into my apache modules directory as mod_wsgi37.so
I ran ldd on this file, and have a .conf file loading it into httpd like this:
LoadFile /home/myUser/pythonbuild/lib/libpython3.7m.so.1.0
LoadModule wsgi_module modules/mod_wsgi37.so
Then within my VirtualHost I have:
WSGIDaemonProcess wsgi group=www threads=12 processes=2 python-path=/var/
www/wsgi-scripts python-home=/var/www/wsgi-scripts/wsgi_env3
WSGIProcessGroup wsgi
WSGIScriptAlias /test /var/www/wsgi-scripts/test.py
from my virtual environment:
sys.prefix:'/var/www/wsgi-scripts/wsgi_env3'
sys.real_prefix:'/home/myUser/pythonbuild'
When I switch to the system-installed mod_wsgi/python combo (remove python-home line from WSGIDaemonProcess, and change the .conf file to load the original mod_wsgi.so) it works fine. It seems like some path variables aren't getting set properly. Is there another way to set variables like PYTHONHOME that I'm missing? How can I fix my install?
I had a very similar issue and I found that my manually specified LoadModule wsgi_module "/path_to_conda/" was being ignored because the previously apache-wide wsgi mod was being loaded. You can check if wsgi.* is present in /etc/apache2/mods-enabled.
If that is the case, consider a2dismod wsgi to disable the apache wsgi that loads the wrong python.
As I ran into this problem recently, I found a solution that works in my environment.
I don't work with a virtual environment, but have a non-standard python installation in my home folder (compiled and installed without root access) - this should be similar to a virtual environment.
My virtual host config is structured as follows:
WSGIPythonHome /home/myuser/usr/
<VirtualHost *:80>
...
WSGIDaemonProcess wsgi home=/path/to/my/project/folder processes=10 threads=10
WSGIScriptAlias / /path/to/my/project/folder/wsgi.py
WSGIProcessGroup wsgi
</VirtualHost>
First, I omitted python-path completely. Further, WSGIPythonHome should point to the parent folder of the bin/, lib/ and include/ directories with the python libraries.
I made the mistake to point it towards the bin/ folder.
Consequentially, WSGI could not load the default libraries, even when I added them to the python path manually via WSGIPythonPath.
I have my apache config set up to point to my virtualenv, but when i load the page and look at the error log it gives the following error:
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
apache2 000-default.conf file:
WSGIDaemonProcess project python-home=/home/django/config/env python-path=/usr/local/bfx/Databases/project
WSGIProcessGroup project
WSGIScriptAlias / /usr/local/bfx/Databases/project/project/wsgi.py
Basically, it will work if I install django, and all my django packages on my server, but what is the point of the virtual env?
Thanks
Virtualenv allows to create isolated environments. So you could create and run multiple projects with different versions of the same library without conflicts, for example.
You have to install all libraries in the server too. Virtualenv do not create a bundle nor deploy it.
I'm using mac os x and trying to get the official flask tutorial to work with Apache, but when I attempt to open the site in localhost on my browser it results in a 404: The requested URL / was not found on this server. I followed these directions for configuring mod_wsgi for flask. I've run the app using the built in server with flask so I know the app itself works.
The following is the resulting error in the Apache error log
[negotiation:error] [pid 7563] [client ::1:50509] AH00687: Negotiation: discovered file(s) matching request: /Library/WebServer/Documents/flaskr/flaskr.wsgi (None could be negotiated).
Here is what I have in my flaskr.wsgi file located in /Library/WebServer/Documents/flaskr/flaskr.wsgi
import sys
sys.path.insert(0, '/Library/WebServer/Documents/flaskr')
from flaskr import app as application
I have the following in my httpd.conf file
Listen 80
<VirtualHost *>
ServerName localhost
WSGIDaemonProcess flaskr user=_www group=_www threads=5
WSGIScriptAlias / /Library/WebServer/Documents/flaskr/flaskr.wsgi
<Directory /Library/WebServer/Documents/flaskr>
WSGIProcessGroup flaskr
WSGIApplicationGroup %{GLOBAL}
Require all granted # httpd 2.4 syntax as noted in the guide
</Directory>
</VirtualHost>
LoadModule wsgi_module /usr/local/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-darwin.so
WSGIPythonHome /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6
From terminal when I run sudo apachectl -M it displays wsgi_module (shared). If I comment out the code in my httpd.conf file that I've listed above, the wsgi_module goes away from the enabled modules list, so unless there's something I'm not aware of mod_wsgi seems to be enabled successfully, but as I've mentioned I get a 404 message when trying to view the site.
EDIT
I don't think there's anything wrong with my Apache configuration. I tried this tutorial for getting flask up and running on Apache and it worked. I'll update once I figure out what I did wrong with the "flaskr" app.
Edit - found the problem
Turns out my flaskr.wsgi file was in the wrong directory. It was supposed to be in /Library/WebServer/Documents/flaskr/flaskr/flaskr.wsgi.
The official Flask tutorial I referenced uses the following directory structure
flaskr <----Initially put my `flaskr.wsgi` file in this directory
init.py
flaskr <----Changed to this directory and it worked
flaskr.py
flaskr.db
flaskr.wsgi
Also changed the system path to sys.path.append('/Library/WebServer/Documents/flaskr/flaskr')
I'm having a hard time deploying a Bottle app. I've tried using some of the suggested answers in past questions but I can't seem to get this working. I end up with a 500 Internal Server Error
This is my set up.
Ubuntu 16.04
Apache
libapache2-mod-wsgi-py3
Python 3.5
My .wsgi and app.py file sit at:
/var/www/bottle_app/
app.wsgi
app.py
app.wsgi is as follows
import os
# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))
import bottle
# ... build or import your bottle application here ...
import app
application = bottle.default_app()
app.py is as follows
from bottle import route
#route('/')
def hello():
return 'Hello world'
Apache .conf file:
<VirtualHost *:80>
ServerName example.com
WSGIDaemonProcess bottle_app user=bottle group=www-data processes=1 threads=5
WSGIScriptAlias / /var/www/bottle_app/app.wsgi
<Directory /var/www/bottle_app>
WSGIProcessGroup bottle_app
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
When I run python3 app.py, nothing is returned (I'm assuming this is expected)
When I run python3 app.wsgi I get:
Traceback (most recent call last):
File "app.wsgi", line 3, in <module>
os.chdir(os.path.dirname(__file__))
FileNotFoundError: [Errno 2] No such file or directory: ''
My Apache error logs show the following errors.
Target WSGI script '/var/www/bottle_app/app.wsgi' cannot be loaded as Python module
Exception occurred processing WSGI script '/var/www/bottle_app/app.wsgi
Traceback (most recent call last):
File "/var/www/bottle_app/app.wsgi", line 7, in <module>
import app
ImportError: No module named 'app'
I did this on a clean Ubuntu install under user bottle with sudo privileges. This is probably the 10th time I've rebuilt using different suggestions from other questions from users who had similar problems. I was trying to avoid having to post a question that would seem like duplicate. Any help would be greatly appreciated.
Before you import your app module in the app.wsgi file, try:
import sys
sys.path.insert(0, '/var/www/bottle_app')
A cleaner way might be to make use of the home or python-path parameters to the WSGIDaemonProcess entry in the Apache configuration.
WSGIDaemonProcess bottle_app user=bottle group=www-data processes=1 threads=5 python-path=/var/www/bottle_app
The __file__ isn't absolute, so if you need to get it's location for this type of purpose (where a controlling process like Apache might be doing funny things with paths) try:
os.chdir(os.path.dirname(os.path.abspath(__file__)))
I recently moved my Django project to Apache server. I am facing a few issues with respect to dependency modules being inaccessible after moving the project to Apache.
Here are my configuration files:
This is my bemoss.conf file in the sites-available directory of Apache:
WSGIPythonPath /home/kruthika/workspace/bemoss_web_ui
WSGIPythonPath /home/kruthika/workspace/rtunetwork/volttron
WSGIPythonPath /home/kruthika/workspace/bemoss_web_ui/helper
<VirtualHost *:80>
WSGIScriptAlias / /home/kruthika/workspace/bemoss_web_ui/bemoss.wsgi
ServerName bemoss.com
Alias /static /home/kruthika/workspace/bemoss_web_ui/static
<Directory /home/kruthika/workspace/bemoss_web_ui/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Here is my bemoss.wsgi file:
import os
import sys
sys.path = ['/home/kruthika/workspace']+sys.path
print sys.path
os.environ['DJANGO_SETTINGS_MODULE']='bemoss_web_ui.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
My project is accessing a few more python files from another project. I added a reference to those in my .conf file above and in settings.py file as given below.
PROJECT_DIR = os.path.dirname(__file__)
print PROJECT_DIR
sys.path.insert(3,os.path.join(PROJECT_DIR,'ZMQHelper'))
sys.path.insert(1,os.path.join(PROJECT_DIR,'helper'))
sys.path.insert(2, '/home/kruthika/workspace/rtunetwork/volttron')
print sys.path
This is my project folder definition:
When I try to access a link, whose views.py file refers to the above mentioned dependencies, it throws a import module error as given below.
My question here is how to refer to my dependent modules/python classes so that the files are imported properly.
All these imports were working fine when I executed the project on Django's development server. Is there some Apache configuration I am missing or doing wrong? I am new to server configurations and I think I am missing something here.