I am new to Django framework and Python. I installed Python Wamp server and downloaded mod_wsgi. I follow these steps.
I am in confused whether I configured it correctly since when I stop the wamp server then also the http://127.0.0.1:8000/ works correctly.
Have you considering reading any of the official mod_wsgi documentation at:
http://www.modwsgi.org
including its quick configuration guide.
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
We would then need to now what configuration you set in Apache for mapping your application and a better explaination of the problem you are seeing including any error messages in browser or Apache error logs.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi is the answer it has a windows vc10 binary.
If you can be bothered getting the latest wampserver (or at lest one compiled with vc10):
Add you your env ;C:\Python27;C:\Python27\Scripts
wget http://peak.telecommunity.com/dist/ez_setup.py (or just down loaded it to you user folder)
python ez_setup.py
easy_install pip
pip install django
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi (put the appropriate with your apache moduales (currently has Apache 22 and 24)
In your http.config:
LoadModule wsgi_module modules/mod_wsgi.so
To test start a project:
django-admin.py startproject mysite
python manage.py runserver 83 # (or some other test port that's not 80)
All that I did I got from this youtube
Edit: So when you want to stop testing on port 83 and use Apache on port 80
you need to set WSGIPythonPath as mentioned here (I didn't bother with that page to much) and WSGIScriptAlias. The main guide to do that is here although #Jisson's wamp guide has that too and shows windows paths etc which I at first found useful too :)
Related
I want to configure my python project to make use of apache,
All the configuration settings I have done to have my project to run apache as its server did not work but it was producing
ModuleNotFound error, but when I checked using pip list I saw that the package was installed. However when I run python manage.py runserver ipaddress:8000
it worked perfectly without any error. This show that there is configuration which was not working.
However all tutorials I have studied used apache2 directory as the location where their configuration takes place.
But when I checked apache2 directory I discovered that it was pointing to apache directory and if I tried to enter
into apache2 directory it would redirect me to apache directory so all my work is taking place in apache directory and not apache2 directory.
How can I get my project to make use of apache server and probably access apache2 as it is done in all the tutorials.
There's multiple ways, and not clear tutorials or anything online on how to run a fundamentally basic python script with apache.
mod_python? cgi? wsgi?
Does something need to be installed with python?
It's really confusing. I've been working on it for hours.
Flow
Client accesses a web page, say http://example.com/mangojuice (issue 1). Your server (apache) should know mangojuice referes to /etc/www/superhightechjuice/mango.py. Now this python file should be executed (issue 2). Apache should know .py is supposed to be executed and not served plain. But Python does not know when to wakeup and run. So another entity is needed (issue 3).
Solutions to the three issues (interfaces) are handled by mod_wsgi:
WSGI is inherited from the CGI concept (which was used for executing perl scripts and php scripts) to extend to Python scripts (with additional features). mod_wsgi is how Graham Dumpleton implemented it in Apache and is now a standard.
Issue 1 - Conf file which does the mapping - /etc/apache2/conf-available/wsgi.conf
Issue 2 - Install mod_wsgi - during installation, it updates apache configuration files to inform that .py should be executed; along with a host of other things
Issue 3 - Function - application
Code
def application(environ, start_response):
status = '200 OK'
message = b"Hello World" #Prefix b is useful to convert string to bytestring, which is needed by HTTP
response_header = [('Content-type', 'text/html')]
start_response(status, response_header)
return [message]
Reason
When you setup mod_wsgi, it solves issue 1 by having a mapping file wsgi.conf. It solves issue 2 by updating .conf file of apache and also other OS based settings. For Issue 3, it tells apache, I am a middleware whenever I see reference to 'application', I will inform you and you both can talk (Apache and Python). This is how mod_wsgi helps.
Steps to setup mod_wsgi
Install mod_wsgi for Apache2
sudo apt install libapache2-mod-wsgi
Restart Apache to refresh all updates
apachectl restart
Create the mapping file
vi /etc/apache2/conf-available/wsgi.conf
Update the mapping file with url and local path
WSGIScriptAlias /mangojuice /etc/www/superhightechjuice/mango.py
Create the actual code at /etc/www/superhightechjuice/mango.py
Code sample same as mentioned above. start_response tells mod_wsgi that requests are incoming. mod_wsgi talks with Apache and lets your code through.
Reference:
Official mod_wsgi documentation
I have in my Apache 2 applications: Django app and MoinMoin app. The first one is running now with Python3.4 and the second one (MoinMoin) with Python2.7
When running dpkg:
ruben#babylon:/var/log/apache2$ dpkg -l | grep wsgi
rc libapache2-mod-wsgi 3.4-4ubuntu2.1.14.04.2 amd64 Python WSGI adapter module for Apache
ii libapache2-mod-wsgi-py3 3.4-4ubuntu2.1.14.04.2 amd64 Python 3 WSGI adapter module for Apache
but Apache can't run the 2 modules at the same time. Django (Python3) is working but MoinMoin (Python2.7) not. How can I fix that?
As you were told already in:
Virtual environment not recognized in WSGIPythonPath
you cannot do that within a single Apache instance.
The simple answer as was described is to run a separate WSGI server such as mod_wsgi-express, or you can use gunicorn our something else as well, and set it up behind the main Apache instance it with Apache proxying to it.
There are a lot of details around doing this and as also suggested, you are better off asking on the mod_wsgi mailing list if you want to do this with mod_wsgi.
If don't wish to use the mod_wsgi mailing list, then you can find some information in:
http://blog.dscpl.com.au/2015/06/proxying-to-python-web-application.html
http://blog.dscpl.com.au/2015/07/redirection-problems-when-proxying-to.html
It talks about proxying to backend WSGI application running in Docker, but all the same principles apply as to setting up the proxy fronted and the issues that arise.
To make my question clear:
I have had wamp installed, and it brought Apache. Will this Apache be used by others like Django?
If the wamp Apache is enough for others, its Apache is in wamp directory C:\wamp\bin\apache, not sth like C:\programs file...It is ok for django
If I have to install Apache manually for django, will the step be install Apache, install mod_wsgi?
Any help would be greatly appreciated
Strictly interpreted, Django doesn't "use" Apache. Apache is just one way to direct requests (via mod_wsgi, for example) to your django app and returns the result to the user.
The existing Apache install will be fine. It doesn't matter where it is as long as it's running and reachable.
You will need to install mod_wsgi and configure it so that it knows about your Django app.
You can find documentation for configuring Apache and mod_wsgi here:
https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/
You don't need Apache at all at this point. For development, things work much better if you use the built in development server, as described in the tutorial.
I am of the PHP background and just have started to learn Django and Python (and loving it). I always used to install WAMP server for PHP development.
Now I dont know how do I configure Django to use PostgreSQL i.e how to make both communicate with each other. I have run some 'hello world' scripts with django. Curretly I have installed Python, django and PostgreSQL. here is the version information
Python : 2.7.2 & 3.2 (i have installed both)
Django : 1.3.1
PostgreSQL : 9.1.2
Apache : 2.2 (..this is from WAMP server)
Os : Ms Windows 7 32-bits (x86)
Since django has builtin development server is it at all necessary to have apache installed and use it instead of that one? If we use the built-in server how we are supposed to configure it for PostgreSQL?.
It is not necessary to have apache installed to develop on django. In fact it is often easier to use the development server because it is single threaded, lightweight, and extremely easy to use. python manage.py runserver 0.0.0.0:8080 to run on localhost port 8080, and your code is easily debuggable.
In django you dont configure your server for a database. You configure your project for a database. All database configurations are kept in the settings.py file located in your main project. Page one of the tutorial explains how to set up a database for your django prject. YOu have to specify, database name, host, port, user and password in your settings.py file.
https://docs.djangoproject.com/en/dev/intro/tutorial01/#database-setup
I would suggest walking through the django tutorial as it addresses most of the issues in setting up development on a new django project.
https://docs.djangoproject.com/en/dev/intro/tutorial01/
I recently deployed a Django based project and found this tutorial to be very helpful and concise.
Django virtualenv Apache2 mod_wsgi
And if you have CentOS, then you can install mod_wsgi as mentioned here:
Django Deployment - Setup mod_wsgi on CentOS
Getting Django to run on Apache requires getting Python to interpret that, you can do this with WSGI. follow the tutorial found here:
https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi
there are other methods to deploy this, you can find here:
https://docs.djangoproject.com/en/dev/howto/deployment/