Hello I am having a problem with Django trying to get it deployed on a server using apache. for some reason when I write this information in my httpd.conf file.
<location "/mysite">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug off
PythonPath "['/user/local/src/djcode','/user/local/src/djcode/mysite'] + sys.path"
</Location>
I get this error when I restart apache.
Syntax error on line 3 of /etc/apache2/httpd.conf:
Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
Any ideas?
this error is pretty much self explanatory (second line is important to you):
Invalid command 'PythonHandler', perhaps misspelled
or defined by a module not included in the server configuration
PythonHandler is a command unknown by apache. it's a "module command" known by mod_python. so if missing it says invalid command (OR defined by module not in...).
so make sure mod_python is installed.
you might know it anyways, but just follow this document http://docs.djangoproject.com/en/dev/howto/deployment/modpython/
Also, i recommend you use mod_wsgi instead of mod_python. See deprecation warning on top of this page: http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/
Support for mod_python will be
deprecated in a future release of
Django. If you are configuring a new
deployment, you are strongly
encouraged to consider using mod_wsgi
or any of the other supported
backends.
python_mod is not installed or not configured in httpd.conf.
If you have installed it, then add this line below in httpd.conf:
LoadModule python_module modules/mod_python.so
Related
Trying to deploy a django project on apache (2.2) on Debian 7.
Using Django 1.8 and a virtual environment with python3.4.
Getting the following error:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named _psycop
I have tried the suggestions pointed out here, and here.
Here is my apache conf.
(following lines are nested within VirtualHost scope)
#WSGI configuration for ds_monitor django project
Alias /static /home/pkaramol/Applications/timeds/ds_monitor/static_root
<Directory /home/pkaramol/Applications/timeds/ds_monitor/static_root>
Allow from all
</Directory>
<Directory /home/pkaramol/Applications/timeds/ds_monitor/ds_monitor>
<Files wsgi.py>
Allow from all
</Files>
</Directory>
WSGIDaemonProcess ds_monitor python-path=/home/pkaramol/Applications/timeds/ds_monitor:/home/pkaramol/Applications/timeds/venv_p34dj18/lib/python3.4/site-packages
WSGIProcessGroup ds_monitor
WSGIScriptAlias /ds_monitor /home/pkaramol/Applications/timeds/ds_monitor/ds_monitor/wsgi.py
and this outside VirtualHost scope (to enable production - time virtual environment)
WSGIPythonPath /home/pkaramol/Applications/timeds/ds_monitor:/home/pkaramol/Applications/timeds/venv_p34dj18/lib/python3.4/site-packages
Another issue is the following line present in apache's log stack trace
File "/usr/lib/python3.2/importlib/_bootstrap.py", line 821, in _gcd_import
loader.load_module(name)
Why is it using system's python 3.2?
Have I done s.th wrong in terms of pointing the virtualenv path correctly in wsgi confs?
In any case, the psycopg2 module is also installed in the system (not only in virtualenv)
Seems very weird but the whole issue most likely had to do with the python version that mod_wsgi was compiled against.
I had downloaded / configured / installed version 4.5.2 of mod_wsgi from here but forgot to configure with the appropriate python version.
So I run through the whole process again (starting from unzipping the original tarball) and configuring as follows:
./configure --with-python=/usr/bin/python3.5
Restarted apache and problem solved.
my first question for this site, i hope it goes well!!
I have, ubuntu, apache2, python, django and mod_python.
All is installed properly.
I have created a website project which works properly when i run it locally.
But i cant get it working the same way on apache.
I can access my website project directories, but i cant access my website projects URL's
I think this has something to do with incorrectly configuring my directives in the httpd.conf file. Also when i type the server name in the web browser i get a server not found
a quick rundown:
My project lives in /home/jamie/mysite
django, apache, modpython on root directory
in /etc/apache2/sites-available/http.conf i have:
NameVirtualHost 111.22.33.44
<VirtualHost 111.22.33.44>
ServerName www.example.com
DocumentRoot /home/jamie/mysite
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Location "/mysite">
SetHandler python-program
PythonHandler django.core.handlers.modpython
#removed line -PythonHandler mod_python.publisher- didnt work#
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonPath "['/home/jamie/', '/usr/local/lib/python2.6/dist-packages'] + sys.path"
PythonAutoReload On
PythonDebug On
</Location>
</VirtualHost>
ANybody that can help me i will give 1 BILLION DOLLARS to
ok akonsu cheers for this.
http//localhost/templates points to my templates folder and shows all the files and subdirectories. http//localhost/templates/homepage.html will show the homepage.html located in the templates folder with all the ugly django tags that go with it.
I want run my website app on apache the same way as if i ran it locally, via the urls.
example. http//localhost/homepage would point directly to the file homepage.html which is located in the templates folder as this is how it is set out in the urls.py file and would not show the ugly django tags.
If i do type in http//localhost/homepage via the apache server i get the url /homepage does not exist on this server
The django book tells me to point DJANGO_SETTINGS_MODULE to my apps settings file, which i have done 'DJANGO_SETTINGS_MODULE mysite.settings' The settings file points to the urls file which points to the views file which in turn renders with template files and so on and so forth. Thus if i typed http//localhost/homepage it should work as homepage has been configured properly in my urls.py file. I believe i have done what they have asked but still no luck. Either im getting the DJANGO_SETTINGS_MODULE part wrong or starting with /localhost is wrong.
I dont know what difference this makes but if i change the servername in the httpd.conf file to say www.blabla.com it wont throw an error when i restart apache server, meaning it's configured right. But when i type www.blabla.com in the browser i get an error saying this site does not exist.
try removing PythonHandler mod_python.publisher
I just moved my site to an actual apache server (was developing locally before) and the site can't seem to find the urls.py file. basically what happens is that the homepage works, which is weird in itself considering that if i go to any url, e.g. website/about/, i will get a 404 error with text {'path': u'about/'}.
I tried ROOT_URLCONF set to mysite.urls and just urls, and if i move the urls.py it will continue to behave the same way.
I don't know if its related but I also can't seem to access my site media folder, it seems as though the server is still reading it in its old path, but the settings.py file is correct. (tried restarting apache, rebooting server, etc..)
I would be more worried about it not finding the media directory, that's pure apache. If that part of the equation isn't working, nothing else will. Work with apache's httpd.conf until you can browse to the media directory correctly first.
Update:
I copied in my working conf file and substituted your values. Your django.root might need to be "" or not set at all, as I've found that it shouldn't end with a /:
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE fikdusite.settings
PythonOption django.root ""
PythonDebug On
PythonPath "['/django_apps/', '/django_apps/fikdusite/'] + sys.path"
</Location>
And make sure that the .profile of the user that apache runs your site as, has:
export DJANGO_SETTINGS_MODULE='fikdusite.settings'
export PYTHONPATH=$PYTHONPATH:/django_apps:/django_apps/fikdusite
First, don't use mod_python, use mod_wsgi.
Secondly, don't forget that you need to restart Apache every time you make a code change in Django.
Error can be seen at: http://djaffry.selfip.com:8080/
I had a project working great, but I had all the files under /var/www/ and with my limited understanding it's bad, according to django's site:
"If your background is in PHP, you’re probably used to putting code under the Web server’s document root (in a place such as /var/www). With Django, you don’t do that. It’s not a good idea to put any of this Python code within your Web server’s document root, because it risks the possibility that people may be able to view your code over the Web. That’s not good for security.
Put your code in some directory outside of the document root, such as /home/mycode."
So I went to /home/tipu/stuff/ and executed django-admin.py startproject twingle. Then I went to apache and did
<VirtualHost *:8080>
ServerName tweet_search_engine
DocumentRoot /home/tipu/stuff/twingle/
</VirtualHost>
<Directory /home/tipu/stuff/twingle>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /home/tipu/stuff/twingle
PythonDebug On
PythonPath "['/home/tipu/stuff/', '/home/tipu/stuff/twingle/'] + sys.path"
</Directory>
Now I am getting a 403 Forbidden error.. any idea what I'm doing wrong? I'm newer to Linux (CentOS) and django, so I could be over looking some very simple things.
This is almost certainly just an access rights issue. The Apache user needs rights to access all the directories in the path to your project - home, home/tipu, home/tipu/stuff, home/tipu/stuff/twingle, and so on. You'll need to find out what user Apache is running as, and grant read rights to those directories.
As Ignacio suggests, /srv is probably a better place to put this - but the same rights issues still apply.
Well, under /home is not the right place, thanks to SELinux. Put the app under /srv instead.
I am trying to setup my development environment on my local vista machine (django+apache+mod-python+postgres) and for some reason I can't load the settings.
Everything works on the built-in server but not under apache.
Here is my httpd.conf
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE movies.settings
PythonOption django.root /movies
PythonDebug On
PythonPath "['C:/django'] + sys.path"
</Location>
And Error:
ImportError at /
No module named main.urls
Request Method: GET
Request URL: http://localhost/
Exception Type: ImportError
Exception Value:
No module named main.urls
Exception Location:
C:\Python25\lib\site-packages\django\utils\importlib.py in import_module, line 35
Python Executable: C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\bin\httpd.exe
Python Version: 2.5.4
Python Path: ['C:/django', 'C:\\Windows\\system32\\python25.zip',
'C:\\Python25\\Lib', 'C:\\Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\bin', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2/_externals']
Where does your code for your project reside? The parent of the folder that contains your project should be on the Python path. Assuming main is your project name, and it's in C:\django\projects\main\ you'd need to have c:\django\projects\ on your python path.
Either that, or main.urls should be movies.urls in your settings.py.
I know that you asked this question a couple of weeks ago, but if you're still looking for help, you might try ServerFault. If you have success, please report back here!