I want use django on my ubuntu localhost with apache 2.4. I installed mod_wsgi using
sudo aptitude install libapache2-mod-wsgi
I want point my app written in django
My /etc/apache2/sites-available/wiersze.td.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName wiersze.td
#DocumentRoot /
WSGIScriptAlias / /home/s/py/django/kitty/kitty/wsgi.py
Alias / /home/s/py/django/kitty/kitty/
Alias /adminmedia/ /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/
<Directory "/home/s/py/django/kitty/kitty/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
after enable my site and added hosts I see my files inside kitty directory. Why I cant see my index view?
I think there is problem with alias. Remove following line, restart Apache and retry browsing your site:
Alias / /home/s/py/django/kitty/kitty/
Thanks
Related
I've been trying to deploy a Django app on Ubuntu 18.04 using Apache2 for the past couple of days now, and it still doesn't work.
My apache2 config is:
<VirtualHost *:1337>
<Directory /var/www/LGSM_webpanel/LGSM_webpanel>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/LGSM-error.log
CustomLog ${APACHE_LOG_DIR}/LGSM-access.log combined
WSGIScriptAlias / /var/www/LGSM_webpanel/LGSM_webpanel/wsgi.py
WSGIDaemonProcess LGSM_webpanel python-path=/var/www/LGSM_webpanel
WSGIprocessGroup LGSM_webpanel
DocumentRoot /var/www
</VirtualHost>
However, for some reason, when I access http://localipofthemachine:1337 I just get the google chrome error Connection refused.
Now, the server works when I use manage.py runserver, and I can fully access it, but when I use apache, I just get this error.
The apache logs are also empty by the way.
Thanks in advance for your help
First of all, you need to add Listen 1337 in the virtual host configuration, i.e.
Listen 1337
<VirtualHost *:1337>
# your configuration
# etc
</VirtualHost>
Second, make sure that the apache user www-data can access your webapp files by running chown www-data:www-data -R /var/www/LGSM_webpanel.
I am having difficulty troubleshooting this issue. I have a Django app running on an Ubuntu 14.04 server (with Apache 2.4 and mod_wsgi for Python 3.4). It connects to SQL Server via pymssql.
In development, the app works fine. I query the database, and the database returns the expected results.
In production (under the Apache user), however, the script hangs at the exact point that a database query is made. My browser (Chrome or Firefox) shows a spinning wheel that continues to spin as long as the browser window is open.
I have the following in my apache2.conf file:
ServerName localhost
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
WSGIScriptAlias / /home/production_code/school/school/wsgi.py
# Python virtualenv home
WSGIPythonHome /home/production_code/python3env
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
And the following in my sites-enabled/000-default.conf file:
<VirtualHost *:80>
ServerAdmin *****#school.edu
ServerName localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/ /home/production_code/school/static/
<Directory /home/production_code/school/>
Require all granted
</Directory>
<Directory /home/production_code/school/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/production_code/school/static>
Require all granted
</Directory>
</VirtualHost>
Does anyone have any idea what might be causing this or how I might troubleshoot this? The Apache error logs and access logs are not particularly helpful in this situation, since a response to the request is never rendered. Similarly, Django debugging is also not useful here.
Instead of:
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
use:
WSGIDaemonProcess application python-path=/home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
WSGIProcessGroup application
WSGIApplicationGroup %{GLOBAL}
A key part of this is the WSGIApplicationGroup directive, with it being set to %{GLOBAL}.
This is to get around faulty third party extension modules for Python that don't work in sub interpreters and which can fail with a dead lock or crash.
See:
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
It is also recommend you go back to using daemon mode. It is generally not a good idea to use embedded mode.
http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
on django 1.8
In apache error logs am getting
File "..../python2.7/site-packages/django/utils/lru_cache.py", line 28
fasttypes = {int, str, frozenset, type(None)},
SyntaxError: invalid syntax
googling around this seems to be an error you get when running django 1.7+ and not meeting the minimum python requirement of 2.7.
however
$ python --version
Python 2.7.3
here is the relevant parts of apache virtual host config.
<VirtualHost <some_ip>:80>
WSGIDaemonProcess some_process python-path=/path/to/django-project/main-django-app:/path/to/virtual-env/site-packages/ threads=15 display-name=%{GROUP}
WSGIProcessGroup some_group
WSGIScriptAlias / /path/to/django-project/main-django-app/wsgi.py
<Directory /path/to/django-project/main-django-app>
<Files wsgi.py>
Order deny,allow
# Require all granted
# for Apache < 2.4
Allow from all
</Files>
</Directory>
</VirtualHost>
does anyone have any idea what the issue might be?
You need to install the mod_wsgi for your python version.
If you have not access to the apache installation, mod_wsgi can be installed directly in your virtualenv using pip. Then it can be loaded in your server settings using:
Global settings:
LoadModule wsgi_module /path/to_your_env/path/to/mod_wsgi.so
WSGISocketPrefix run/wsgi
WSGIDaemonProcess 385969
Virtualhost:
WSGIScriptAlias / "/path/to/your/wsgi.py"
<Location />
WSGIProcessGroup 385969 # this value must be identical to WSGIDaemonProcess
</Location>
Finally, I your wsgi.py file, you'll have to activate the virtualenv.
I am trying to set up apache with an existing django project using the tutorial in django site here. My os is Ubuntu, and everything is installed (django apache2 libapache2-mod-wsgi)
My conf file
WSGIPythonPath /home/avlahop/development/django/rhombus2/rhombus/
<VirtualHost *:80>
ServerName myrhobmus.com
ServerAlias www.myrhombus.com
WSGIScriptAlias / /home/avlahop/development/django/rhombus2/rhombus/rhombus/wsgi.py
</VirtualHost>
After I created the conf file I ran the a2ensite Ubuntu command for enabling the site.
Putting WSGIPythonPath inside VirtualHost gives me an apache configtest failure
Files inside directive inside directory (as described in the example) gives me the same failure
If I go to www.myrhombus.com I get a Google chrome could not find the specified address message.
What am I doing wrong? Every tutorial on the Internet is using the old file.wsgi while now Django creates this for you but it is a python file with .py extension. How can I serve my django with apache? And If I wanted to go production at my own server where would you put django code and where would you put template files?
EDIT: I am only getting the Index of / page. Is there something I have to do with mysites location in terms of permissions? Could you give me a working example of an django site apache conf file?
I use Django 1.8 and I successfully deployed my project Apache server. I followed basic concept like you and enable Apache this module early.
enable module
You can my project structure this question.Refer this question to understand project structure
--------------this is my virtual host file----------------------------------
WSGIPythonPath /home/umayanga/Desktop/view_site/serialKey_gen_site:/home/umayanga/Desktop/view_site/serialKey_gen_site/myvenv/lib/python3.4/site$
<VirtualHost *:80>
ServerAdmin admin#key.com
ServerName key.com
ServerAlias www.key.com
Alias /templates/ /home/umayanga/Desktop/view_site/serialKey_gen_site/templates/
Alias /static/ /home/umayanga/Desktop/view_site/serialKey_gen_site/static/
<Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/static">
Require all granted
</Directory>
<Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/templates">
Require all granted
</Directory>
WSGIScriptAlias / /home/umayanga/Desktop/view_site/serialKey_gen_site/mysite/wsgi.py
<Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/mysite">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
-----------------wsgi.py---------------------------------------
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
I think this will be help to you.
I have a virtual machine running peppermint os 2 (basically ubuntu).
I've been trying to follow the following tutorial: http://jeffbaier.com/articles/installing-django-on-an-ubuntu-linux-server/
and so far everything has worked out as the tutorial has stated. My Apache httpd.conf file looks like the following:
ServerName localhost
MaxRequestsPerChild 1
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonPath "['/home/<my_user_name>/django_projects'] + sys.path"
SetHandler None
SetHandler None
SetHandler None
SetHandler None
Whenever I try and and go into "localhost/", it shows me the /var/www/ folder (the index.html file that says "It works!") and not a django startpage that should come up. The contents of my /var/www are "admin_media" and "media"
What do I need to do?
Thank you.
try mod_wsgi or uwsgi, it's easier to config, robust, and much faster.
you could also get help at django doc - use django with mod_wsgi
as you are using ubuntu, the install of mod_wsgi is easy:
sudo apt-get install libapache2-mod-wsgi
if this does not have mod-wsgi enabled, do as following:
cd /etc/apache2/mod_available
cp mod_wsgi.* ../mod_enable
sudo service apache2 restart
for using mod_python, the apache config is:
ameVirtualHost *:80
NameVirtualHost *:8000
Listen 80
Listen 8000
WSGIDaemonProcess xxxx display-name=%{GROUP}
WSGIProcessGroup xxxx
<VirtualHost *:80>
ServerName xxxx
WSGIScriptAlias / /home/xxx/xxxx/xxxx.wsgi
Alias /js "/home/xxx/xxxx/xxxx/public/js"
<Location "/js">
SetHandler None
</Location>
<Directory "/home/xxx/xxxx/xxxx/public/js">
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:8080
<VirtualHost *:8080>
WSGIScriptAlias / /home/xxxx/xxxx/wsgi_handler.py
#WSGIDaemonProcess xxxx_com22 user=xxxx processes=1 threads=10
#WSGIProcessGroup xxxx_com1
Alias /upload/ "/home/xxxx/xxxx/upload/"
<Directory /home/xxxx/xxxx/upload/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Listen 8080
and for using uwsgi, my recommend is using nginx + uwsgi, if you are interesting, I'll post the tutorial and configuration.