mod_wsgi application entry point? What and Where is it? - django

I'm trying to figure out if I have set up my mod_wsgi in Embedded mode or Daemon mode and found this page "Reloading Source Code" on the mod_wsgi wiki. It provides a handy script which will tell you what your setup is.
However I'm just not sure about the below sentence from the guide?
"If you are not sure whether you are using embedded mode or daemon
mode, then substitute your WSGI application entry point with sic[the below script]"
What or where is my 'WSGI application entry point'? Where can I copy the script to?
Thanks
Ubuntu: 12.04.5 LTS
Apache: 2.2.22
mod_wsgi Version: 3.3-4ubuntu0.1

i would say WSGI application entry point is the wsgi.py script which is the Gate (stands also for Gateway) from apache into django app and vise versa
it is like
browser < - > server < - > wsgi < - > django
without wsgi the server can serve (render) normal html files but not django app. for this, you need wsgi (Web Server Gateway interface) which is a Gate between django and server
hope this helps

It means wherever the WSGIServerAlias is pointing to, so for Django the wsgi.py file.

Related

Django site on Webfaction - how the flow of information works, and integrating with Pycharm remote dev

I have been learning Django in the development mode for a two months and I am up to speed with most basic aspects of python + django now. However, I was using the built-in runserver till this time
Now, I have got a Webfaction hosting account and wanted to know the following
1) Webfaction sets up the project with a certain Django version (say 1.6.4) and Python version (say 2.7) initially
The project directory (for say project MYAPP) is /<>/webapps/MYAPP
When the site is running in production mode, how does the apache server know which Python version, and which site-packages versions to use with the MYAPP source code to render the site?
I can see that the MYAPP folder has a lib/python2.7 folder, however when I am connected to SSH terminal, and do a "which python", i see :
which python
/usr/local/bin/python
so, do I take that this is the Python executable that is being used for rendering the website instead of the one in webapps/MYSITE/lib/python2.7 folder? How does the information/data flow about which programs to use during rendering the site with apache mod_wsgi work?
2) I was using a virtualenv in the development mode during testing. How do I use this on webfaction in production mode?
3) I am using Pycharm IDE. It worked well for the development mode. I can see that it has a remote interpreter configuration and a Deployment setting/option.
The python path that the remote interpreter settings tool detects automatically is the python executable at /usr/local/bin/python
Is this fine, or should I be pointing it to the more local python2.7 in the webapps/lib folder?
Thanks a lot of the answers and pls let me know if you need any supplemental info
Note to the OP: This should really be three separate questions.
1) For WebFaction, your Django app will use the Python version (and libraries, etc.) defined in:
~/webapps/<appname>/apache2/conf/httpd.conf
Specifically, you'll want to look at what is defined for WSGIPythonPath (which should mostly match up with WSGIDaemonProcess unless you modify the config and are doing something strange).
Note that which python just tells you what the default python is in your shell. This has nothing to do with the config file for the webapp.
2) You may want to expand on this as to exactly what your use case is and why the default Django webapp created by WebFaction doesn't fit your needs. But the short answer is:
Create a virtualenv on your WebFaction account.
Install Django, etc. into the virtualenv.
Edit the httpd.conf file I mentioned above to use your virtualenv instead.
I've done this with both a Django webapp made via the WebFaction control panel and via a custom mod_wsgi webapp. So it does work. Just make sure to use the right Python version when making your virtualenv.
3) I don't use PyCharm so I can't answer this (one reason why this question should be split up).

Do I need to restart apache each time after changing code

I am deploying a Django app on webfaction. All code are uploaded, but sometimes there are still some modification I need to make. My workflow is edit local file in Pycharm and sync the change to remote server (Apache). So, for example, do I need to restart apache every time after changing views.py for the change to take effects?
If you are using modpython yes, you have to reload apache every time or your modules will not be reloaded.
If you are using apache and mod_wsgi then touching the wsgi module is enough.
As other already suggested nginx + gunicorn (or better nginx + uwsgi) are better options than apache + mod_python to serve your django app.
In fact, you do not have to, you just have to « touch » the wsgi.py file (if you are using the mod_wsgi apache2 module). You can do it by uploading the wsgi.py file every time you upload something.

Installing, configuring and developing for django on ubuntu 10.10 server

I wanted to start getting into developing with Django, however, I am unable to figure out how to make it work. I have installed apache2, I have tried many tutorials on configuring apache to run Django, but I just do not understand how it all works together. Can someone give me a dummies guide on how to install it, how things work, and why?
The best way to link between Django and Apache is using WSGI. You will need to install the mod_wsgi apache module to do this.
Next step: modify the apache configuration file to designate where you want the root of your django website.
WSGIScriptAlias / /path/to/mysite/apache/myApp.wsgi
Next, you should create the wsgi file. This is what initializes your django application. An example wsgi file looks like this
import sys
import os
sys.path.insert(0,os.path.normpath(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0,'/path/to/directory/containing/application')
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'twitmycity.settings'
application = django.core.handlers.wsgi.WSGIHandler()
Once you have this, restart apache
sudo /etc/init.d/apache2 restart
Now, point your browser to the root directory where you established the wsgi handler. This should bring you to the root to your django application. I hope this helps!
Also note, when you make a change to your application, you need to refresh the modified time on the wsgi file to prevent wsgi from just using a cache version of the django application. To do this, execute
touch myApp.wsgi

how to restart single apache site on a ubuntu vps rather than all sites

I've got a ubuntu vps and apache mod wsgi installed and serving my django sites.
however i have to restart all of apache rather than the site i have amended and its going to be a bit shonky if i tell clients that i have restarted their site cos i updated another site.
is there a tutorial somewhere to teach me how to configure this? i couldnt find one in googles keywords soup.
I'm already using virtualenvs if it helps.
Assuming you use mod_wsgi in daemon mode on UNIX/Apache 2.X system to run Django and have shell access to your machine all you need to do is touch the wsgi configuration for your project.
touch your_project.wsgi
See mod_wsgi documentation on Reloading Source Code and Django - mod_wsgi wiki for more references.

Apache Django Mod_Wsgi Sessions Development Environment

I'd like to know how I can maintain sessions while developing on my local machine (django, apache, mod-wsgi).
Each time I make updates to python code I need to restart Apache for the changes to take effect.
Read the documentation. See:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
It explains in a great amount of detail about source code reloading in Apache/mod_wsgi.
Just touching the WSGI script file will not do anything if you aren't use mod_wsgi in the correct mode.
And yes you can use Apache/mod_wsgi as a development server if you set it up with daemon mode and code change monitor as documented in that page.
As for MaxRequestsPerChild, that is not recommended and will only work in embedded mode of mod_wsgi and not in daemon mode.
You only need to touch your WSGI script for the changes to take effect.
Put this in your Apache conf file.
MaxRequestsPerChild 1
This will force Apache to reload the python files after each request.