WSGIDaemonProcess causes 'You don't have permission error' - django

Hello I am trying to deploy my django application on digital ocean server. I did run the application inside a virtual environment and it all worked fine. But I want my domain to point to my application and followed this tutorial. But the problem is when the apache conf file is edited with the following code i get the error.
Forbidden You don't have permission to access / on this server.
This is how my directly looks
+root
+myproject
+myproject
settings.py
urls.py
wsgi.py
+static
manage.py
+myprojectenv
Here is my WSGI.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
Here is my Apache Default conf file 000-default.conf
<VirtualHost *:80>
#ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
Alias /static /home/user/alpha/static
<Directory /home/user/alpha/static>
Require all granted
</Directory>
Alias /static /home/root/myproject/static
<Directory /home/root/myproject/static>
Require all granted
</Directory>
<Directory /home/root/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/root/myproject/myprojectenv python-path=/home/root/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /home/root/myproject/myproject/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
I am not experience enough to find out what is causing the error. If i remove below lines in the apache conf file. I get Ubuntu home page when i try to access my server
WSGIDaemonProcess myproject python-home=/home/root/myproject/myprojectenv python-path=/home/root/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /home/root/myproject/myproject/wsgi.py

Your Python code will run as the Apache user. As a result it likely will not have access to files under home directories as they don't have permissions on them that allows access by others.
You should move stuff from out of the home directories and put it under somewhere like /var/www/project.
See:
http://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#access-rights-of-apache-user

Related

django deployment with apache and mod_wsgi

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.

Django deploy to Production in Ubuntu 16.04

I'm fairly new to django , i have to deploy the project to production mode in ubuntu 16.04. I have installed wsgi with apache2 and included the system path to the django project and python site-packages.
My sites-enabled/000-default.config is
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName myproject.com
ServerAlias www.myproject.com
Alias /static /var/www/html/TEST/myproject/static
<Directory /var/www/html/TEST/myproject/static>
Require all granted
</Directory>
<Directory /var/www/html/TEST/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/var/www/html/TEST/newenv python-path=/var/www/html/TEST/myproject:/var/www/html/TEST/newenv/lib/python3.5/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/html/TEST/myproject/myproject/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and my wsgi file
import os , sys
sys.path.append('/var/www/html/TEST/myproject/')
sys.path.append('/var/www/html/TEST/newenv/lib/python3.5/dist-packages/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
when i run the link i am getting Internal Server Error(505)
and i have checked the error in the error log ,it's showing me from
django.core.wsgi import get_wsgi_application
[wsgi:error] ImportError: No module named django.core.wsgi
Can someone please help me with this ? i have googled and checked out all other options and solutions . Thanks in advance
Instead of:
WSGIDaemonProcess myproject python-home=/var/www/html/TEST/newenv \
python-path=/var/www/html/TEST/myproject:/var/www/html/TEST/newenv/lib/python3.5/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/html/TEST/myproject/myproject/wsgi.py
all you should need is:
WSGIDaemonProcess myproject python-home=/var/www/html/TEST/newenv \
python-path=/var/www/html/TEST/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/html/TEST/myproject/myproject/wsgi.py
You don't need to add the site-packages directory.
In the wsgi.py file you don't need:
sys.path.append('/var/www/html/TEST/myproject/')
sys.path.append('/var/www/html/TEST/newenv/lib/python3.5/dist-packages/')
as python-home and python-path on WSGIDaemonProcess achieve same result.
Another issue is that you have put your Django project code under the directory /var/www/html. You should not put it there. That is the default DocumentRoot directory. If you were to uncomment WSGIScriptAlias, someone could download your source code. So is better to not put your code under that directory.
Now neither of those things should make a difference as far as solving your problem, as the first just gets of redundant settings. The second is just changing to better practices.
At this point, the only reason can see why Django module could not be found is if the permissions on the directories/files are such that the user that Apache runs your code as cannot read them. So check permissions on /var/www/html/TEST/newenv.

how to resolve You don't have permission to access / on this server

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.

Python Djangocms Install App WSGI vs 8000 port

I follow the tutorial http://docs.django-cms.org/en/develop/introduction/plugins.html, when I install the Polls App as indicated it is visible on 8000 port But not in WSGI/Apache mode (error message no module polls). To see the APP polls I need to copy Polls application files in the default root directory. Idem with the Aldryn Blog News. I guess I have to specify some more PATH in wsgi mode to help Python to find the modules. Where and how to do that in my Virtualenv, to be also effective when I deploy all the stuff on a remote platform ?
Thanks for any help
Thank you for your interest. IMHO I don't think the problem is on APACHE configuration, everything is OK and DjangoCMS works without polls. Herinafter the conf file, the domain is a local virtual one.
DocumentRoot "/var/www/djangocms"
WSGIScriptAlias / /var/www/djangocms/default/wsgi.py
ServerName djangocms.net
Alias /static/ /var/www/djangocms/default/static/
Options +ExecCGI
Order Allow,Deny
Allow from All
ErrorLog "logs/errordjangocms_log"
LogLevel error
Marcel
Here is a working config i use
<VirtualHost *:80>
ServerName iot.mydomain.com
ServerAlias iot
WSGIDaemonProcess iot.local python-path=/home/name/PycharmProjects/iotdata
WSGIProcessGroup iot.local
WSGIScriptAlias / /home/name/PycharmProjects/iotdata/iotdata/wsgi.py process-group=iot.local
#WSGIPythonPath /home/name/PycharmProjects/iotdata
Alias /static/ /home/name/PycharmProjects/iotdata/static/
<Directory /home/name/PycharmProjects/iotdata>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/name/PycharmProjects/iotdata/static>
Require all granted
</Directory>
</VirtualHost>

How to deploy Django with mod_wsgi on Debian machine?

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