on django 1.8
In apache error logs am getting
File "..../python2.7/site-packages/django/utils/lru_cache.py", line 28
fasttypes = {int, str, frozenset, type(None)},
SyntaxError: invalid syntax
googling around this seems to be an error you get when running django 1.7+ and not meeting the minimum python requirement of 2.7.
however
$ python --version
Python 2.7.3
here is the relevant parts of apache virtual host config.
<VirtualHost <some_ip>:80>
WSGIDaemonProcess some_process python-path=/path/to/django-project/main-django-app:/path/to/virtual-env/site-packages/ threads=15 display-name=%{GROUP}
WSGIProcessGroup some_group
WSGIScriptAlias / /path/to/django-project/main-django-app/wsgi.py
<Directory /path/to/django-project/main-django-app>
<Files wsgi.py>
Order deny,allow
# Require all granted
# for Apache < 2.4
Allow from all
</Files>
</Directory>
</VirtualHost>
does anyone have any idea what the issue might be?
You need to install the mod_wsgi for your python version.
If you have not access to the apache installation, mod_wsgi can be installed directly in your virtualenv using pip. Then it can be loaded in your server settings using:
Global settings:
LoadModule wsgi_module /path/to_your_env/path/to/mod_wsgi.so
WSGISocketPrefix run/wsgi
WSGIDaemonProcess 385969
Virtualhost:
WSGIScriptAlias / "/path/to/your/wsgi.py"
<Location />
WSGIProcessGroup 385969 # this value must be identical to WSGIDaemonProcess
</Location>
Finally, I your wsgi.py file, you'll have to activate the virtualenv.
Related
i want open django server using apache and mod_wsgi.
i wrote down as below
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi
and create django project and app and i add my bot in setting.py
and create virtual environment and using
and add below code in seoultech/wsgi.py /django = mydirctory/ seoultech=project/bot =app /
import os, sys
sys.path.append('/home/django')
sys.path.append('/home/django/venv/lib/python2.7/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "seoultech.settings")
application = get_wsgi_application()
and cd /etc/apache2/site-available/000-default.conf
add code
WSGIDaemonProcess seoultech python-path=/home/django/seoultech=home/django
/venv/lib/python2.7/site-packages
<VirtualHost *:80>
ServerAdmin webmaster#localhost
WSGIScriptAlias / /home/django/seoultech/wsgi.py
<Directory /home/django/seoultech>
<Files wsgi.py>
Require all granted
</Files>
</Directory
</VirtualHost>
but sudo apachectl-k start i got error
'AH00526: Syntax error on line 1 of /etc/apache2/sites-enabled
/000default.conf:Invalid command 'WSGIDaemonProcess', perhaps misspelled
or defined by a module not included in the server configuration Action '-k
start' failed.The Apache error log may have more information.'
im looking forward to help
Place WSGIDaemonProcess inside of VirtualHost to get rid of this error.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
WSGIDaemonProcess seoultech python-path=/home/django/seoultech=home/django
/venv/lib/python2.7/site-packages
WSGIScriptAlias / /home/django/seoultech/wsgi.py
<Directory /home/django/seoultech>
<Files wsgi.py>
Require all granted
</Files>
</Directory
</VirtualHost>
so i'm about to lunch my first django website , i currently have a server that has been configured to host php websites and i've decided to test a simple empty project to get familiar with the process
so the python version in this server is bit old (2.6) so i couldn't install latest version of django , i installed 1.6 and since it's just a test that's not important (im going to upgrade python version when my website is ready to lunch )
so i've installed django and created a new project called testing in this dire
/home/sdfds34fre/public_html/
which you can see using this domain
http://novadmin20.com
and after reading documentation on django (unfortunately they have removed doc for 1.6 and i had to use 1.9) and wsgi i've updated my httpd.conf like this
<VirtualHost 111.111.111.111:80>
ServerName 111.111.111.111
DocumentRoot /usr/local/apache/htdocs
ServerAdmin somemeail#gmail.com
<IfModule mod_suphp.c>
suPHP_UserGroup nobody nobody
</IfModule>
<Directory /home/sdfds34fre/public_html/testing/testing>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
WSGIProcessGroup testing
WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py
</VirtualHost>
but even after restarting httpd service when i go to
http://novadmin20.com/testing/
all i see is directory list , am i missing something ?
here is my wsgi.py file
"""
WSGI config for testing project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
DocumentRoot directive is the main root of your problem. (ref)
try this config:
<VirtualHost 111.111.111.111*:80>
ServerName novadmin20.com
WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py
<Directory /home/sdfds34fre/public_html/testing/testing>
<Files wsgi.py>
Order deny,allow
Require all granted
WSGIProcessGroup testing
</Files>
</Directory>
</VirtualHost>
I have installed the following on my Windows machine (everything is 64bit):
Python 3.4.3
Apache 2.4.16
mod_wsgi 4.4.13
Then I installed Django(v1.8.3) in a virtual environment using virtualenv. Using django-admin I created two project and I created two VirtualHost for that. And everything is working perfect. Now I would like to use a different environment for the second project but though the Windows doesn't support WSGIDaemonProcess and WSGIProcessGroup I don't know how to do that.
WSGIPythonPath "C:/_pythonDev/project1;C:/_pythonDev/project2;C:/_pythonDev/env1/Lib/site-packages"
<VirtualHost *:80>
ServerName one.local.com
WSGIScriptAlias / "C:/_pythonDev/project1/project1/wsgi.py"
<Directory "C:/_pythonDev/project1/project1">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName two.local.com
WSGIScriptAlias / "C:/_pythonDev/project2/project2/wsgi.py"
<Directory "C:/_pythonDev/project2/project2">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
So, If someone knows how to run Django projects in different environment please guide me.
Solution: click this link
You need to address two things.
Don't set WSGIPythonPath in the Apache configuration. Activate the Python virtual environment and set sys.path from the WSGI script file.
Change the WSGI script file so as not to use setdefault() in os.environ as that screws things up.
For reading see:
http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html
http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html
So i'm trying to deploy a simple website using django, Apache, and wsgi. I wrote my conf file using the django guide (https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/) and this previous answer (Deploying Django on Apache and WSGI) but when I restart Apache I get an syntax error on line 3 stating WSGIPythonPath cannot occur within the VirtualHost section, once removed Apache restarted successfully but still does not redirect to the appropriate django website I created even after changing the hosts files so that it redirects back to my server.
Apache Version: 2.4.7
Python Version: 2.7.6
Django Version: 1.8.3
<VirtualHost *:80>
WSGIScriptAlias / /var/www/mywebsite/mywebsite/wsgi.py
WSGIPythonPath /var/www/mywebsite
ServerAdmin my_email#gmail.com
ServerName mywebsite.com
ServerAlias www.mywebsite.com
<Directory /var/www/mywebsite/mywebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
move the line with WSGIPythonPath to the httpd.conf location
I want use django on my ubuntu localhost with apache 2.4. I installed mod_wsgi using
sudo aptitude install libapache2-mod-wsgi
I want point my app written in django
My /etc/apache2/sites-available/wiersze.td.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName wiersze.td
#DocumentRoot /
WSGIScriptAlias / /home/s/py/django/kitty/kitty/wsgi.py
Alias / /home/s/py/django/kitty/kitty/
Alias /adminmedia/ /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/
<Directory "/home/s/py/django/kitty/kitty/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
after enable my site and added hosts I see my files inside kitty directory. Why I cant see my index view?
I think there is problem with alias. Remove following line, restart Apache and retry browsing your site:
Alias / /home/s/py/django/kitty/kitty/
Thanks