I am having trouble setting Django with Apache on Mac OSX Lion (10.7.2). I created a Django project as per the tutorial and can run it on the development server. Now I want to run it locally on my Mac with Apache. I created the two files indicated below.
apache_django_wsgi.conf
WSGIDaemonProcess django
WSGIProcessGroup django
Alias /site_media/ "/Users/David/Dropbox/sites/walble/media/"
<Directory "/Users/David/Dropbox/sites/walble/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/Library/Python/2.7/site-packages/django/contrib/admin/media/"
<Directory "/Library/Python/2.7/site-packages/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
WSGIScriptAlias /walble "/Users/David/Dropbox/sites/walble/apache/walble.wsgi"
<Directory "/Users/David/Dropbox/sites/walble/apache">
Allow from all
</Directory>
walble.wsgi
import os
import sys
sys.path.append('/Users/David/Dropbox/sites/walble')
sys.path.append('/Users/David/Dropbox/sites')
os.environ['DJANGO_SETTINGS_MODULE'] = 'walble.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
In httpd.conf, I enabled
LoadModule wsgi_module libexec/apache2/mod_wsgi.so and then added the following line.
Include /Users/David/Dropbox/sites/walble/apache/apache_django_wsgi.conf
I restarted Apache and then in the browser I typed in http://localhost/walble but I get a forbidden message like so
Forbidden
You don't have permission to access /walble on this server.
Apache/2.2.20 (Unix) DAV/2 mod_wsgi/3.3 Python/2.7.1 PHP/5.3.6 with Suhosin-Patch Server at localhost Port 80
Any suggestions on what I might be doing wrong?
This is a common permissions problem. The Apache user does not have execute permissions on the walble.wsgi file.
Related
In order to deploy my django project, i've downloaded httpd and mod_wsgi. To configure this module, I've also downloaded apxs and gcc and I've followed this tutorial :
https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
And then I've found in the django documentation :
https://docs.djangoproject.com/fr/2.0/howto/deployment/wsgi/modwsgi/
a way to deploy my project.
So I actually have this wigs.py :
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ProjetIML.settings")
application = get_wsgi_application()
And this httpd.conf :
WSGIScriptAlias / /home/ninon/ProjetIML/ProjetIML/wsgi.py
WSGIPythonPath /home/ninon/ProjetIML
<Directory /home/ninon/ProjetIML/ProjetIML>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Then I've restart the apache server with "apachectl restart" and when I try to access my site with localhost:80 nothing append. Did I miss something ?
I've seen many posts explaining that they have coded files like "django.wsgi" but I haven't found anything about it in the django documentation.
I've also tried to add a Virtual host like this :
<VirtualHost *:80>
WSGIScriptAlias / /home/ninon/ProjetIML/ProjetIML/wsgi.py
WSGIPythonPath /home/ninon/ProjetIML
<Directory /home/ninon/ProjetIML/ProjetIML>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
But the apache server didn't want to restart.
I've followed the instructions on Django website for configuring Apache with my Django app on a CentOS 7 server. This included building mod_wsgi from sources to work with the installed python3.4.
Apache restarts without errors but when I hit my app with the URL
http://example.com/myapp/
I get a 503 error like:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.2.15 (CentOS) Server at example.com Port 80
I'm not sure how I troubleshoot what's wrong here. Can anyone help?
Details of the config:
My django app lives at /mnt/net/django/myapp
I've added the file wsgi.conf to my apache conf.d directory and it looks like this:
#LoadModule wsgi_module modules/mod_wsgi.so
# use python34 pip installes mod_wsgi
LoadModule wsgi_module "/usr/lib64/python3.4/site-packages/mod_wsgi/server/mod_wsgi-py34.cpython-34m.so"
#WSGIPythonHome "/usr"
Alias /robots.txt /mnt/net/django/myapp/static/robots.txt
Alias /favicon.ico /mnt/net/django/myapp/static/favicon.ico
Alias /media /mnt/net/django/myapp/media/
Alias /static/ /mnt/net/django/myapp/static/
<Directory /mnt/net/django/myapp/static>
Order deny,allow
Allow from all
</Directory>
<Directory /mnt/net/django/myapp/media>
Order deny,allow
Allow from all
</Directory>
# Allows URLs like example.com/myapp to forward to django
WSGIScriptAlias /myapp /mnt/net/django/myapp/myappsite/wsgi.py process-group=example.com
# Use the virtual env for the myapp site
#WSGIPythonHome /mnt/net/django/myapp/env-myapp-py3-4
# Need to use WSGIDaemon
WSGIDaemonProcess example.com python-home=/mnt/net/django/myapp/env-myapp-py3-4 python-path=/mnt/net/django/myapp
#WSGIPythonPath /mnt/net/django/myapp
<Directory /mnt/net/django/myapp/myappsite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
How to use Django with Apache and mod_wsgi -- follow this: I have done it myself many times, it is very straight forward.
Tip: Create a document and record everything you do whilst setting this up, this way if it doesn't work then you can retrace your steps, but if it does work... Great, you have your very own guide to setting up an Apache server for Django.
Solved my problem (mostly)
The problem is that mod_wsgi with a daemon process tries to write a socket file into the apache logs directory and permissions are denied.
Solution is to tell apache another place to write the socket like this:
WSGISocketPrefix /var/run/wsgi
Hi I need help in integrating django with apache and mod_wsgi on centos6.
I am getting following error every time---"Forbidden You don't have permission to access / on this server."
My django project path= /home/mchauras/esapp/eswebsite
my apache version is 2.2.15
my .conf file looks like this----
<VirtualHost *:80>
DocumentRoot /home/mchauras/esapp/eswebsite/
Alias /static /home/mchauras/esapp/eswebsite/esapp/static
<Directory /home/mchauras/esapp/eswebsite/esapp/static>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory /home/mchauras/esapp/eswebsite/eswebsite>
<Files wsgi.py>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess esapp python-path=/home/user/myproject:/home/mchauras/esapp/eswebsite/myvenv/lib/python3.5/site-packages/
WSGIProcessGroup esapp
WSGIScriptAlias / /home/mchauras/esapp/eswebsite/eswebsite/wsgi.py
ErrorLog /home/mchauras/esapp/eswebsite/error.log
CustomLog /home/mchauras/esapp/eswebsite/access.log combined
</VirtualHost>
my wsgi.py file is like this---
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/mchauras/esapp/eswebsite')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eswebsite.settings")
application = get_wsgi_application()
its looks like you did not login as a administrator user or maybe you need to changes and enable all file permission in the path
This specific error is usually always caused by the user that Apache runs as not being able to access the WSGI script file. It is not enough to just make the file itself readable to others. All the directories from '/' down to that directory must also be accessible to the user Apache runs as. As home directories for users are not usually readable by others, the Apache user cannot see into it. You are better off moving the application directory outside of your home directory.
Another possible cause, although one which usually results in a slightly different error, is having SELinux enabled where the profile for Apache httpd server on SELinux doesn't allow access to the directories where your application is.
I have installed apache2, mod_wsgi on my Debian machine and added this on my apache2.conf file:
WSGIScriptAlias /home/zurelsoft/Documents/workspace/genalytics/genalytics/wsgi.py
WSGIPythonPath /home/zurelsoft/Documents/workspace/genalytics
<Directory /home/zurelsoft/Documents/workspace/genalytics/genalytics>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
My project name is genalytics. I am using Django 1.5. There's already wsgi.py available. What should I do run the django with mod_wsgi and where should I give the path of my static files. Thanks
Edit
I have this on my apache.conf file:
Listen 8000
Alias /static/ /home/zurelsoft/Documents/workspace/genalytics/fileupload/static
<Directory /home/zurelsoft/Documents/workspace/genalytics/fileupload/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /home/zurelsoft/Documents/workspace/genalytics/fileupload/static
<Directory /home/zurelsoft/Documents/workspace/genalytics/fileupload/static>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
But when I run try to start apache I get this error:
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
Presuming that you have set up everything correctly, you don't have much left to do.
In your application root, create a file named django.wsgi and write the following code.
import os
import sys
sys.path.append('/path/to/your/app')
os.environ['PYTHON_EGG_CACHE'] = '/path/to/your/app/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Now, add a virtual host in your apache configuration for serving static and other files and add the following lines:
WSGIScriptAlias / /path/to/your/app/django.wsgi
<Directory /path/to/your/app>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /path/to/your/app/robots.txt
Alias /favicon.ico /path/to/your/app/favicon.ico
Alias /images /path/to/your/app/images
Alias /static /path/to/your/app/static
ErrorLog /path/to/your/app/logs/error.log
CustomLog /path/to/your/app/access.log combined
Remember to restart apache.
You can check this and this links for complete information. Also, if you need to know how to add virtual host, check this out.
Hope that helps.
There are a number of howtos on the web, most of which work with current Django versions, but I was unhappy with their lack of conformance with Django's current docs and found the easiest path to follow these instructions:
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/
There it says: 'As of Django version 1.4, startproject will have created wsgi.py for you' - which looks like this:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
So now it's wsgi.py that connects to mod_wsgi, which you installed with aptitude, and django.wsgi is deprecated.
Now we want to honor the debian method of configuring apache sites, so instead of putting the following code into httpd.conf, as django-docs propose, we create a dj-myapp file in /etc/apache2/sites-available, activate it with a2ensite dj-myapp and disable default with a2dissite default.
The WSGI-directives are written before the virtualhost section:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<VirtualHost *:80>
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
This is for apache 2.2x, for 2.4+ use Require all granted instead of Allow from all.
Finally configure the static file serving, as described in the django docs. The directives are also placed in dj-myapp. For the admin static files this line worked for me:
Alias /static/admin /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin
create file called app.conf in /etc/apache2/sites-available.The app.conf:
WSGIPassAuthorization On
WSGIPythonPath /home/brms/manage/web/brms
WSGIDaemonProcess pyramid user=brms group=brms threads=4 \
python-path=/usr/local/lib/python3.4/dist-packages/
<VirtualHost *:80>
<Directory /home/brms/manage/>
<Files wsgi.py>
WSGIProcessGroup pyramid
Require all granted
</Files>
</Directory>
Alias /meetingApp /var/www/meetingApp
</VirtualHost>
WSGIScriptAlias / /home/brms/manage/wsgi.py
Enable this siteļ¼sudo a2ensite app.conf
Restart Apache: sudo service apache2 restart
Just set up a 64 bit ubuntu EC2 instance using the Bitnami DjangoStack image.
So far I have installed a few python dependencies and removed the Project django app which was created by default. I created a new app with 'django-admin.py startproject projectname'. I then followed the instructions here: http://wiki.bitnami.org/Components/Django, attempting to setup apache.
Here is my projectname.conf file:
Alias /static "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/admin/static"
<Directory '/opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/'>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /URL_mount_point "/opt/bitnami/apps/django/scripts/projectname.wsgi"
<Directory '/opt/bitnami/apps/django/scripts'>
Order allow,deny
Allow from all
</Directory>
Here is my projectname.wsgi
import os, sys
sys.path.append('/opt/bitnami/apps/django/django_projects')
sys.path.append('/opt/bitnami/apps/django/django_projects/projectname')
os.environ['DJANGO_SETTINGS_MODULE'] = 'projectname.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Here are the last three lines of my httpd.conf:
Include "/opt/bitnami/apache2/conf/ssi.conf"
Include "/opt/bitnami/apache2/conf/bitnami/httpd.conf"
Include "/opt/bitnami/apps/django/conf/projectname.conf"
After doing this and restarting apache, hitting mydomain.com/projectname still comes up with a 404 (the Bitnami landing page comes up just fine at mydomain.com).
Am I missing something here? Are my paths in projectname.wsgi incorrect (I have not strayed from the default Bitnami directory structure). Or is there some additional step I am missing here?
You should be accessing:
http://mydomain.com/URL_mount_point
Since it appears you have not shown your original configuration, hard to say whether that is the issue or whether is a typo of sorts.
I added this to my httpd.conf
WSGIScriptAlias / /opt/bitnami/apps/django/scripts/projectname.wsgi
<Directory '/opt/bitnami/apps/django/django_projects/projectname'>
Order allow,deny
Allow from all
</Directory>
and that seemed to fix it.