I have configure mod_wsgi along with Apache 2 and tested with my Debain Squeeze 6. I need to put my code under /var/www directory as a extension .wsgi.
Now, I want to configure Django with mod_wsgi. How do I do it? Do I put my every files under /var/www. Is there a security issue or something? Can someone tell me step by step to configure django with mod_wsgi and where would be better to put the DJango codes? Thank you! P.S I have intermediate Django knowledge.
Here are a couple of links that you can use. The first one has proven the most useful for me as it is very detailed!
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi
Hope it helps!
EDIT:
Regarding security, as long as you provide access to the apache user (or www-data, depending on your linux distribution) (chown and chgrp) for all files in your /var/www/html/your_django_project you should not have any issues. Do NOT run anything as superuser.
Be careful to allow the apache user to write your log files, wherever they are. You could get irrelevant errors which could be caused by that.
Also, setup apache to serve django media files if you don't want to end up with media-less pages :-)
There's a pretty good instruction set on the documentation site.
Related
I have a domain example.com and I run a standard Apache there (serving static files and PHP). I want to run Python served pages on subdomain.example.com.
I managed to configure Apache to do this and there is a Flask app running at subdomain.example.com. However, in the virtual host config file, the whole subdomain is tight to this one single app. I would like to go further and run several different apps on this subdomain.
For example:
subdomain.example.com/app1/ would run /var/www/apps/app1/app.wsgi
subdomain.example.com/app2/ would run /var/www/apps/app2/app.wsgi
and so on...
Furthermore I would like this to be fully automatic, that is when I set up new folder in /var/www/apps/, I could reach the app through the Apache without further configuration.
I can see several ways of doing this:
Configure Apache to route every subdomain.example.com request
to a single "meta app" in Python which would run a specific app
based on given URL.
Do some magic with Apache configuration that would take care of
this automatically.
Maybe use nginx? I don't really have much experience with this,
but someone told me this could solve the problem.
Is there any best practice about how to do this? Thank you.
It looks like you should be able to do this by providing a directory path (in your case, /var/www/apps) to the WSGIScriptAlias directive. Read more here:
https://modwsgi.readthedocs.org/en/develop/configuration-directives/WSGIScriptAlias.html
This seems like a neater solution than using a meta app.
I have been looking at setting up a web server to use Python and I have installed Apache 2.2.22 on Debian 7 Wheezy with mod_wsgi. I have gotten the initial page up and going and the Apache will display the contents of the wsgi file that I have in my directory.
However, I have been researching on how to deploy a Python application and I have to admin, I find some of it a little confusing. I am coming from a background in PHP where it is literally install what you need and you are up and running and PHP is processing the way it should be.
Is this the same with Python? I can't seem to get anything to process outside of the wsgi file that I have setup. I can't import anything from other files without the server throwing a "500" error. I have looked on Google and Bing to try to find an answer to this, but I can't seem to find anything, or don't know that what I have been looking at is the answer.
I really appreciate any help that you guys can offer.
Thanks in advance! (If I need to post any coding, I can do that, I just don't know what you guys would need, if anything, as far as coding examples for this...)
Python is different from PHP in that PHP executes your entire program separately for each hit to your website, whereas Python runs "worker processes" that stay resident in memory.
You need some sort of web framework to do this work for you (you could write your own, but using someone else's framework makes it much easier). Flask is an example of a light one; Django is an example of a very heavy one. Pick one and follow that framework's instructions, or look for tutorials for that framework. Since the frameworks differ, most practical documentation on handling web services with Python are focused around a framework instead of just around the language itself.
Nearly any python web framework will have a development server that you can run locally, so you don't need to worry about deploying yet. When you are ready to deploy, Apache will work, although it's usually easier and better to use Gunicorn or another python-specific webserver, and then if you need more webserver functionality, set up nginx or Apache as a reverse proxy. Apache is a very heavy application to use for nothing but wsgi functionality. You also have the option of deploying to a PaaS service like Heroku (free for development work, costs money for production applications) which will handle a lot of sysadmin work for you.
As an aside, if you're not using virtualenv to set up your Python environment, you should look into it. It will make it much easier to keep track of what you have installed, to install new packages, and to isolate an environment so you can work on multiple projects on the same computer.
So, I'm running Apache2 on a Linux machine, and I'm trying to serve pages with Django 1.3. I found a guide to do this here.
I have the django.wsgi configured, the settings.py configured, and the database created and successfully in sync with Django. However, when I try to visit the website, I am shown a page served by Apache, instead of Django. I get no errors/warnings at all.
I put print statements in both django.wsgi and settings.py (since they're both just python files), but nothing gets printed.
Does anyone have any idea as to what may be going wrong or any diagnostic steps I might be able to take?
Thanks!
As everyone has said in the comments, you need to add a WSGIServerAlias directive to the Apache configuration before anything will work. Otherwise, Apache can't possibly know to use WSGI to serve your site.
I am new to web development. So be gentle. AND thanks in advance.
I am developing on windows env. and deploying on a linux server w/ Python 2.6.2 installed.
Running apache2.2 as Virtual Host, and I am using mod_wsgi. I plan to serve media files from the same Virtual Host.
I have a django site and I am now ready to deploy. I am stuck, and every site I go to seems to be outdated/incomplete/overmyhead.
https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/
http://www.djangobook.com/en/2.0/chapter12/
...only 2 links as for the newbness
The top link seems to be what I need yet I am still confused on these things:
What does the file structure look like on the server
I cannot change/edit server files myself, I rely on the dba for that
I have django.wsgi, and django.wsgi~, where do those go?
Where do I put my project in relation to those wsgi files?
The httpd.conf file is something that the server has on it? or do I create another?
Do I need to put django in any way shape or form on the server? If so where? And what about the packages like registration, defaults?
Again sorry for the newbness, I have been banging my head for 2 weeks on this.
Any help/links will be greatly appreciated unless they link me to the django-docs. I have read those...A LOT! thanks
Also go read:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
and watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
The latter includes Django examples and talks a bit about locations, permissions etc.
The first of these is even linked to in the document in the Django documentation.
It doesn't matter where the files go. They just have to be readable/executable by the user that the web server is running under.
I don't know what you mean by django.wsgi~, that sounds like a backup file created by your editor - you don't need that.
Yes the httpd.conf is the configuration file for Apache. Some distributions (eg Debian and Ubuntu) split this up into separate files for each site that the server runs. If your administrator is the only one who can edit files, he will know about this already.
Yes, you need Django, and any third-party packages.
#Nathan
An easier option for you while you are learning this is not to really have to many expenses.
I could also suggest you take a look at Heroku - allows you to easily deploy your applications in minutes.
Up until recently they only supported RoR and they have brought in support for Django and Python - they have some really well documented tutorials as well.
I hope this helps
Heroku Django / Python tutorial
I have written up an simple deployment guide for django applications it can be found here. It goes all the way from project setup and deployment. I also have references setup. I honestly believe it answers all your questions, I would give it a look.
Goodluck.
As an experienced PHP programmer I tend to avoid things like Python. However we all must play with the cards we have been dealt with and I now have to work with a Satchmo website.
I have very little python, django and satchmo so I need some help. I'm ok with setting up a development server but I cannot get my website to work on a production server.
I've seen the use of "python manage.py runserver", this solution is even on Stack Overflow. However, when I see this solution there is usually someone saying "I hope you're not using that on production" so I assume this is a very incorrect way to do it. To my frustration the people that seem to know that this command line is insecure, also have no desire to share with the rest of us, just how excatly does one initiate their Satchmo Production server?
Many thanks.
To deploy a Django website on a production server, you have to serve it either with Apache+mod_wsgi, nginx+gunicorn, nginx+uwsgi, or any other server supporting WSGI. The Django documentation has a page on deploying Django on Apache with mod_wsgi, for the other solutions, there are plenty of useful documentation around the web.
runserver is just for development/testing. It won't handle high load, security, etc.
Python.org has docs on how to set up a proper webserver to serve Python code:
http://docs.python.org/howto/webservers.html
Satchmo seems like a django derivative. Setting up django on production is quite easy if your deployment environment is linux with apache then use mod_wsgi which is well documented here if its windows then you can use the pyisapie module and follow the documentation here
Hope that helps