Python Djangocms Install App WSGI vs 8000 port - django

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>

Related

Using my django remotely with a ubuntu server

I want to have access to my Django project from anywhere. For this reason, I have a Raspberry Pi with Ubuntu.
If I run the command python manage.py runserver, it runs the project in http://127.0.0.1:8000/ as default. But this is the localhost of my raspberry/ubuntu and what I want is run the project on my laptop. for this reason I change the 127.0.0.1 for the adress of my server http://xxx.xx.xx.x:8000/ and I run it on my browser. THIS FAILS.
Ok, reading some information I see that I have to open a port to access remotely, for this goal I use the ufw library.
I open the 80 port using ufw,
Now if I write http://xxx.xx.xx.x:80 on my browser, don't fail, appear this,
Apache config:
<VirtualHost *:80>
ServerAdmin admin#djangoproject.localhost
ServerName djangoproject.localhost
ServerAlias www.djangoproject.localhost
DocumentRoot /home/smart/IoTIB_Dashboard
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/smart/IoTIB_Dashboard/static
<Directory /home/smart/IoTIB_Dashboard/static>
Require all granted
</Directory>
Alias /static /home/smart/IoTIB_Dashboard/media
<Directory /home/smart/IoTIB_Dashboard/media>
Require all granted
</Directory>
<Directory /home/smart/IoTIB_Dashboard/IoTIB_Dashboard>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django_project python-path=/home/smart/IoTIB_Dashboard python-home=/home/user/IoTIB_Dashboard/env
WSGIProcessGroup IoTIB_Dashboard
WSGIScriptAlias / /home/smart/IoTIB_Dashboard/IoTIB_Dashboard/wsgi.py
Thus I understand that now is opened.
The problem is that if now I run again my django project as python manage.py runserver 80 and I write again http://xxx.xx.xx.x:80/user_app/login/ in my browser, appears the following,
What I'm doing wrong? I'm newbie and I don't know what I have to do. The objective is to be able to access the project remotely. Can somebody help me?
Thank you very much.

How to set the apache2.conf file for a django project?

I am now deploying a django test project on aws-ec2 and the AMI is Ubuntu18.04 with Python 3.6, Django 2.1, Apache2.
The project is under /var/www/Project and I am trying to add the setting to apache.conf.
The project is simply generated by django-admin startproject Project and I want make sure that when hit the public IP provided by the instance, it should show up the django default page.
WSGIDaemonProcess ubuntu processes=2 threads=12 python-path=/var/www/Project
WSGIProcessGroup ubuntu
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /var/www/Project/Project/wsgi.py
<Directory /var/www/Project/Project>
Require all granted
</Directory>
Now i got the internal server error.
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
I have tried this previously. And it seems like it only works when i use python2.7 with django 1.11.
WSGIScriptAlias / /var/www/Project/Project/wsgi.py
WSGIPythonPath /var/www/Project
<Directory /var/www/Project/Project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
what's wrong with my conf file?
I finally come up with the following solution.
If you are using Apache2, Python2 and Ubuntu18.04 LTS, you can change the apache2.conf file by adding the following:
WSGIScriptAlias / [path_to_wsgi.py]
WSGIPythonPath [path_to_project]
<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
If you want to use the latest Django 2+ version, change the /etc/apache2/sites-available/000-default.conf which is the settings for HTTP port 80. (000-default.conf file can't contains WSGIPythonPath in virtualhost)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
Alias /static [path_to_static_folder]
<Directory [path_to_static_folder]>
Require all granted
</Directory>
<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess [name] python-home=[path_to_virtualenv] python-path=[path_to_project]
WSGIProcessGroup [name]
WSGIScriptAlias / [path_to_project_wsgi.py]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Issue with my Ubuntu Apache Conf file. (Forbidden You don't have permission to access / on this server.)

This below is the conf file for https://github.com/treeio/treeio
I used this method: http://goo.gl/KTdlUT , to configure treeio to my Azure Based Ubuntu VM but still it says: Forbidden You don't have permission to access / on this server.)
<virtualhost *:80>
ServerAdmin abcd#xyz.com
ServerName abcd.net
ServerAlias abcd.net
DocumentRoot "/home/User/treeio"
<Directory /home/Userk/treeio/>
<Directory /home/User/treeio/>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess treeio.djangoserver processes=2 threads=15 display-name=%{GRO$
WSGIProcessGroup treeio.djangoserver
WSGIScriptAlias / /home/User/treeio/wsgi
ErrorLog "/home/User/treeio/log/error.log"
CustomLog "/home/User/treeio/log/access.log" combined
</virtualhost>
It seems like some configurations prefer Django projects to be installed in the /var/www/ directory, even though up until now the home folder had been the recommended location. This seems to make sense from a security perspective.
In addition, Microsoft has the simplest step-by-step instructions which actually work with Unbunto 14.04 in Azure:
http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-python-django-web-app-linux/

Deploying Multiple Django projects on apache with wsgi

I am trying to give a Domain name and run multiple django projects on my apache
<VirtualHost first.site.com:80>
ServerName first.site.com
WSGIDaemonProcess first
WSGIScriptAlias / /opt/project/first/first/wsgi.py process-group=first application-group=%{GLOBAL}
ErrorLog ${APACHE_LOG_DIR}/error.log
<Directory /opt/project/first/first>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost second.site.com:80>
ServerName second.site.com
WSGIDaemonProcess second
WSGIScriptAlias / /opt/project/second/second/wsgi.py process-group=second application-group=%{GLOBAL}
ErrorLog ${APACHE_LOG_DIR}/error.log
<Directory /opt/project/second/second>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
but, second website don't work.
You don't have permission to access / on this server.
Any advice is much appreciated.
Thanks
Are all directories from / down to the directory where the WSGI script files are readable to the Apache user? That is the main reason why you get this error.
Updating Virtual Host Settings from Apache 2.2 to Apache 2.4
Apache 2.2
Order allow,deny
Allow from all
Apache 2.4
Require all granted

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