can't reload apache with wsgi - django

So I'm following the tutorial on Django on how to deploy : https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/
I copypasted this in httpd.conf
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
and now all my websites are redirected to my django app
so I tried puting a VirtualHost around that script, and if I do that I cannot reload apache2. Any idea why or how I should do it?

I don't know how long I've been up working on that problem. But I found something:
WSGIPythonPath /path/to/mysite.com
If I write this line I can't reload apache.
So I removed it, and I wrote:
import sys
sys.path.append('/home/myproject/')
in wsgi.py
and it works :)

Related

LOST on WSGIPythonPath takes one argument, Python module search path

I'm sorry if ask very dumb question.
But I had no idea what i'm doing, I'm just following the tutorial
Link here: https://www.youtube.com/watch?v=F6-yJpPEpoE
Now I'm just trying to start up Apache server to run my Django code in productions
I encounter this error:
C:\WINDOWS\system32>C:/Frontier_Website/Apache24/bin/httpd.exe -k startserver
AH00526: Syntax error on line 542 of C:/Frontier_Website/Apache24/conf/httpd.conf:
WSGIPythonPath takes one argument, Python module search path.
I'm assuming the error is unable to find my python path, something related to python, which apologies I'm not sure what is looking for.
This are the codes in httpd setting:
#python and mod_wsgi setting
LoadModule wsgi_module "c:/users/user/appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIScriptAlias / "C:\Frontier_Website\FrounterWeb postgreDB-the secnond\FrounterWeb\wsgi.py"
WSGIPythonHome C:/users/user/appdata/local/programs/python/python37
WSGIPythonPath C:\Frontier_Website\FrounterWeb postgreDB-the secnond\zigview
<Directory C:\Frontier_Website\FrounterWeb postgreDB-the secnond\zigview\static>
Require all granted
</Directory>
<Directory C:\Frontier_Website\FrounterWeb postgreDB-the secnond\zigview>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
In advance thank you, so much on the help
Use this template to a django app in Apache:
<VirtualHost *:80>
. . .
Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
Require all granted
</Directory>
<Directory /home/user/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/user/myproject python-home=/home/user/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/wsgi.py
</VirtualHost>
WSGIPythonPath is for additional directories to search for Python modules, not neccesssary if you use a virtual env, I guess
Source: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04 (The apache conf works in Windows too)

How to set the apache2.conf file for a django project?

I am now deploying a django test project on aws-ec2 and the AMI is Ubuntu18.04 with Python 3.6, Django 2.1, Apache2.
The project is under /var/www/Project and I am trying to add the setting to apache.conf.
The project is simply generated by django-admin startproject Project and I want make sure that when hit the public IP provided by the instance, it should show up the django default page.
WSGIDaemonProcess ubuntu processes=2 threads=12 python-path=/var/www/Project
WSGIProcessGroup ubuntu
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /var/www/Project/Project/wsgi.py
<Directory /var/www/Project/Project>
Require all granted
</Directory>
Now i got the internal server error.
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
I have tried this previously. And it seems like it only works when i use python2.7 with django 1.11.
WSGIScriptAlias / /var/www/Project/Project/wsgi.py
WSGIPythonPath /var/www/Project
<Directory /var/www/Project/Project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
what's wrong with my conf file?
I finally come up with the following solution.
If you are using Apache2, Python2 and Ubuntu18.04 LTS, you can change the apache2.conf file by adding the following:
WSGIScriptAlias / [path_to_wsgi.py]
WSGIPythonPath [path_to_project]
<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
If you want to use the latest Django 2+ version, change the /etc/apache2/sites-available/000-default.conf which is the settings for HTTP port 80. (000-default.conf file can't contains WSGIPythonPath in virtualhost)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
Alias /static [path_to_static_folder]
<Directory [path_to_static_folder]>
Require all granted
</Directory>
<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess [name] python-home=[path_to_virtualenv] python-path=[path_to_project]
WSGIProcessGroup [name]
WSGIScriptAlias / [path_to_project_wsgi.py]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

django deployment with apache and mod_wsgi

In order to deploy my django project, i've downloaded httpd and mod_wsgi. To configure this module, I've also downloaded apxs and gcc and I've followed this tutorial :
https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
And then I've found in the django documentation :
https://docs.djangoproject.com/fr/2.0/howto/deployment/wsgi/modwsgi/
a way to deploy my project.
So I actually have this wigs.py :
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ProjetIML.settings")
application = get_wsgi_application()
And this httpd.conf :
WSGIScriptAlias / /home/ninon/ProjetIML/ProjetIML/wsgi.py
WSGIPythonPath /home/ninon/ProjetIML
<Directory /home/ninon/ProjetIML/ProjetIML>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Then I've restart the apache server with "apachectl restart" and when I try to access my site with localhost:80 nothing append. Did I miss something ?
I've seen many posts explaining that they have coded files like "django.wsgi" but I haven't found anything about it in the django documentation.
I've also tried to add a Virtual host like this :
<VirtualHost *:80>
WSGIScriptAlias / /home/ninon/ProjetIML/ProjetIML/wsgi.py
WSGIPythonPath /home/ninon/ProjetIML
<Directory /home/ninon/ProjetIML/ProjetIML>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
But the apache server didn't want to restart.

deploy django application on apache server

I'm new to django and deploying apps. I tried to follow this tutorial. Everything worked great except that by the end, instead of the django app I got the depault apache2 page. (If it's matter, I work on ubuntu).
/etc/apache2/sites-available/000-default.conf:
<VirtualHost *:8079>
Alias /static /home/or/myproject/static
<Directory /home/or/myproject/static>
Require all granted
</Directory>
<Directory /home/or/myproject/myproject/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/or/myproject/ python-home=/home/or/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/or/myproject/myproject/wsgi.py
</VirtualHost>
Any suggestions? maybe firewall or something? I'm pretty lost...
[1]: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
So I'm not sure what went wrong but I used this tutorial and it works great (except that I edited '000-default' file instead of 'default' file.

How to deploy Django with mod_wsgi on Debian machine?

I have installed apache2, mod_wsgi on my Debian machine and added this on my apache2.conf file:
WSGIScriptAlias /home/zurelsoft/Documents/workspace/genalytics/genalytics/wsgi.py
WSGIPythonPath /home/zurelsoft/Documents/workspace/genalytics
<Directory /home/zurelsoft/Documents/workspace/genalytics/genalytics>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
My project name is genalytics. I am using Django 1.5. There's already wsgi.py available. What should I do run the django with mod_wsgi and where should I give the path of my static files. Thanks
Edit
I have this on my apache.conf file:
Listen 8000
Alias /static/ /home/zurelsoft/Documents/workspace/genalytics/fileupload/static
<Directory /home/zurelsoft/Documents/workspace/genalytics/fileupload/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /home/zurelsoft/Documents/workspace/genalytics/fileupload/static
<Directory /home/zurelsoft/Documents/workspace/genalytics/fileupload/static>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
But when I run try to start apache I get this error:
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
Presuming that you have set up everything correctly, you don't have much left to do.
In your application root, create a file named django.wsgi and write the following code.
import os
import sys
sys.path.append('/path/to/your/app')
os.environ['PYTHON_EGG_CACHE'] = '/path/to/your/app/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Now, add a virtual host in your apache configuration for serving static and other files and add the following lines:
WSGIScriptAlias / /path/to/your/app/django.wsgi
<Directory /path/to/your/app>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /path/to/your/app/robots.txt
Alias /favicon.ico /path/to/your/app/favicon.ico
Alias /images /path/to/your/app/images
Alias /static /path/to/your/app/static
ErrorLog /path/to/your/app/logs/error.log
CustomLog /path/to/your/app/access.log combined
Remember to restart apache.
You can check this and this links for complete information. Also, if you need to know how to add virtual host, check this out.
Hope that helps.
There are a number of howtos on the web, most of which work with current Django versions, but I was unhappy with their lack of conformance with Django's current docs and found the easiest path to follow these instructions:
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/
There it says: 'As of Django version 1.4, startproject will have created wsgi.py for you' - which looks like this:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
So now it's wsgi.py that connects to mod_wsgi, which you installed with aptitude, and django.wsgi is deprecated.
Now we want to honor the debian method of configuring apache sites, so instead of putting the following code into httpd.conf, as django-docs propose, we create a dj-myapp file in /etc/apache2/sites-available, activate it with a2ensite dj-myapp and disable default with a2dissite default.
The WSGI-directives are written before the virtualhost section:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<VirtualHost *:80>
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
This is for apache 2.2x, for 2.4+ use Require all granted instead of Allow from all.
Finally configure the static file serving, as described in the django docs. The directives are also placed in dj-myapp. For the admin static files this line worked for me:
Alias /static/admin /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin
create file called app.conf in /etc/apache2/sites-available.The app.conf:
WSGIPassAuthorization On
WSGIPythonPath /home/brms/manage/web/brms
WSGIDaemonProcess pyramid user=brms group=brms threads=4 \
python-path=/usr/local/lib/python3.4/dist-packages/
<VirtualHost *:80>
<Directory /home/brms/manage/>
<Files wsgi.py>
WSGIProcessGroup pyramid
Require all granted
</Files>
</Directory>
Alias /meetingApp /var/www/meetingApp
</VirtualHost>
WSGIScriptAlias / /home/brms/manage/wsgi.py
Enable this siteļ¼šsudo a2ensite app.conf
Restart Apache: sudo service apache2 restart