I'm trying to become better with deploying a website from scratch so I setup a new Nanode from Linode using the latest Ubuntu (19.04 I think).
I followed the instructions to install Mezzanine CMS (Django Based) and it all went fine, I was able to run the dev server to test the website fine on port 8000.
I did install UFW and right now only activity on port 80 is not rejected. Also I have mysql database running with Mezzanine not Djangos default SQLlite.
I installed Apache and WSGI. At first Apache would not restart due to some configuration issue which I think I've since worked out.
I have a domain alexmerced which is on godaddy, but I have a DNS "a" records which is pointing to my linodes IP address "mezz.alexmerced.com"
Mezzanine is still a fresh install so I haven't really changed anything outside of the WSGI and settings.py.
I currently get a forbidden error when I type the URL or IP address, the permissions of the application directory is 755.
below are my configuration file settings to see if I made any mistakes.
django_project.conf (the only conf file enabled in the /sites-available/ directory
<VirtualHost *:80>
ServerName mezz.alexmerced.com
ServerAdmin mezzanine#localhost
DocumentRoot /mymezz
WSGIScriptAlias / /mymezz/mymezz/wsgi.py
Alias /static /mymezz/static/
<Directory /mymezz/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
here is the wsgi.py file
"""
WSGI config for mymezz 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.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from mezzanine.utils.conf import real_project_name
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"%s.settings" % real_project_name("mymezz"))
application = get_wsgi_application()
other stuff I read on asked me to add the following to my settings.py
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(PROJECT_ROOT, ".."))
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ["DJANGO_SETTINGS_MODULE"] = settings_module
and
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I never did figure this out with Apache, but I did successfully deploy this blog using Nginx and Uwsgi, just be careful regarding the path your virtual environment once completed I realized that was the problem I was having apache.
Related
So I am trying to migrate my app to a new production server. I'm not getting a reply from the server Apache server when I access it. The server is on AWS and it's a standard Apache config with just one site enabled:
<VirtualHost *:80>
Alias /static/ /home/ubuntu/myapp/myapp/myapp/static
Alias /media/ /home/ubuntu/myapp/myapp/myapp/media
<Directory /home/ubuntu/myapp/myapp/myapp/static>
Require all granted
</Directory>
<Directory /home/ubuntu/myapp/myapp/myapp/media>
Require all granted
</Directory>
<Directory /home/ubuntu/myapp/myapp/myapp>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
WSGIDaemonProcess myapp python-home=/home/ubuntu/myapp/myapp/myapp python-path=/home/ubuntu/myapp:/home/ubuntu/myapp/lib/python3.6/site-packages
WSGIProcessGroup myapp
WSGIScriptAlias / /home/ubuntu/myapp/myapp/myapp/myapp/wsgi.py
ErrorLog /var/log/apache2/myapp_error.log
LogLevel warn
CustomLog /var/log/apache2/myapp_access.log combined
</VirtualHost>
I have made sure that all files are owned by the ubuntu user and that www-data has group rights.
The wsgi file is the original, but I added a print statement to see the folder it's checking for the application:
"""
WSGI config for match2 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, sys
print(sys.path)
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
application = get_wsgi_application()
Eventually, the error log will produce:
Timeout when reading response headers from daemon process 'myapp': /home/ubuntu/myapp/myapp/myapp/myapp/wsgi.py
I'd appreciate any advice.
Timeout when reading response headers from daemon process 'myapp' means your application is taking to long to handle the request. This could be because it is deadlocked, or is waiting on backend service.
Add WSGIApplicationGroup to your virtual host configuration.
<VirtualHost *:80>
# config remaining parts
WSGIApplicationGroup %{GLOBAL}
# config remaining parts
</VirtualHost>
From docs
... forces the WSGI application to run in the main Python interpreter context of each process. This is preferred in this scenario as some third party packages for Python which include C extensions will not run in the Python sub interpreter contexts which mod_wsgi would use by default. By using the main Python interpreter context you eliminate the possibility of such third party packages for Python causing problems.
A similar case link.
Also:
Looking at this,
python-home=/home/ubuntu/myapp/myapp/myapp python-path=/home/ubuntu/myapp:/home/ubuntu/myapp/lib/python3.6/site-packages
I think you have the wrong path for python-home. Make sure python-home path is correctly provided. Activate your virtual environment and run the command to get the python-home path [docs].
python -c 'import sys; print(sys.prefix)'
I am trying to deploy an API built on Django rest-framework using mod_wsgi and WAMP.
When I created a new Django project using 'django-admin startproject Predictor' and deployed it on WAMP, it was working fine as I can see the default Django window.
Now I created an app in the project using 'python manage.py startapp Predictor'
I built an API which accepts GET call and tested it using 'python manage.py runserver' and it was working fine.
Now I started WAMP service again and try to go to 'localhost:8000' it keeps loading. And as soon as I stop WAMP service it crashes saying Unable to connect. Not sure what's happening. Can someone help what's wrong I am doing? FYI I am on windows and I have created and virtual environment for my Django project. This is how my .conf and wsgi files look like
wsgi_windows.py
activate_this = 'C:/Users/DELL/Envs/predenv/Scripts/activate_this.py'
# execfile(activate_this, dict(__file__=activate_this))
exec(open(activate_this).read(),dict(__file__=activate_this))
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('C:/Users/DELL/Envs/predenv/Lib/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('C:/Users/DELL/Envs/predenv')
sys.path.append('C:/Users/DELL/Envs/predenv/Predictor')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Predictor.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Predictor.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd.conf
Listen localhost:8000
Listen [::0]:80
ServerName localhost:8000
LoadFile "c:/python376/python37.dll"
LoadModule wsgi_module "c:/python376/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/python376"
WSGIPythonPath "C:/Users/DELL/Envs/predenv/Predictor"
httpd-vhosts.conf
WSGIPythonPath "C:/Users/DELL/Envs/predenv/Predictor"
<VirtualHost *:80>
WSGIPassAuthorization On
ErrorLog "logs/predictor.error.log"
CustomLog "logs/predictor.access.log" combined
DocumentRoot "C:/Users/DELL/Envs/predenv/Predictor"
WSGIScriptAlias / "C:\Users\DELL\Envs\predenv\Predictor\Predictor\wsgi_windows.py"
<Directory "C:\Users\DELL\Envs\predenv\Predictor\Predictor">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
The issue was it was not able to 'import pandas' in my views.py
To resolve this I have to add this line in my apache 'httpd-vhosts.conf' file
WSGIApplicationGroup %{GLOBAL}
I googled it and i searched everywhere including, but i could't find any solution for my problem.
I'm trying to deploy an django application on a VPS server.
I set up apache2 with my project but when i try to go to http://xxx.xxx.xxx.xxx i always get a 404 not found.
Here are my configurations:
project path : /var/www/master
WSGI file path /var/www/master/projectx249/wsgi.py
Apache2 site conf path: /etc/apache2/site-available/mekhoukh.conf
Apache2 site conf file: for this part this is the last conf i tried on it.
<VirtualHost *:80>
<Directory /var/www/master/projext249>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mekhoukh python-home=/usr/lib/python3.5 python-path=/var/www/master
WSGIProcessGroup mekhoukh
WSGIScriptAlias / /var/www/master/projext249/wsgi.py
i'm using ssh to connect trough the server, i also updated the /etc/hosts with the public ip pointig to the domain name and the localhost ip pointing to it too.
EDIT:
Here's my wsgi.py config file:
import os
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/master/projetx249/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projetx249.settings")
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I am having some issues in configuring the various elements of a mod_wsgi setup. This is my fist time using mod_wsgi so I have been following several tutorials, the main one being a YouTube video Install Django on Apache with mod_wsgi on Linux . From what I understand after following the below steps I should at least see the Django 'It Works' page.
Setup
Ubunto 12.04
Apache 2.2.22
Python 2.7.3
Django 1.6
I have created a WSGI script file firstweb.wsgi in my home directory
/home/firstweb.wsgi
Its contents are
import os
import sys
sys.path = [‘/var/www/firstweb’] + sys.path
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘firstweb.settings’
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I then created a host file for the project located at
/etc/apache2/sites-available/firstweb.conf
Its contents are
<VirtualHost *:80>
ServerAdmin webmaster#firstweb.com
ServerName www.firstweb.com
ServerAlias firstweb.com
WSGIScriptAlias / /home/firstweb.wsgi
Alias /static /var/www/firstweb/static/
<Directory /var/www/firstweb/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I then enabled the configuration file with the command
a2ensite firstweb.conf
I then started my django project.
I went to /var/www/ and used the Django start project command
django-admin.py startproject firstweb
I then restarted my server
sudo service apache2 restart
Lastly I then reconfigured my Apache hosts file to point the domain firstweb.com to my new, local, Django project
/etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu
134.226.38.147 firstweb.com
So with all of this done when I visit www.firstweb.com I should see the Django "It Works!" page
Can anyone tell me what I'm doing wrong?
You haven't listed 'www.firstweb.com' in your /etc/hosts file. Both hosts listed under ServerName and ServerAlias must have a resolvable IP address.
I have a website I've built in django that I'm trying to get working on our corporate Apache server (on debian) for our intranet at my workplace. Unfortunately, Apache keeps returning server errors whenever I try to navigate to my site. Although I can navigate to the statics folder. My Apache config and wsgi script look like the following...
lbirdf.wsgi
import os
import sys
sys.path.append('/home/lbi/rdfweb/web')
sys.path.append('/home/lbi/rdfweb/web/lbirdf')
os.environ['DJANGO_SETTINGS_MODULE'] = 'lbirdf.settings_production'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Apache config
Listen 8080
<VirtualHost *:8080>
ServerName server1
WSGIScriptAlias /rdfweb /home/lbi/rdfweb/web/lbirdf/apache/lbirdf.wsgi
Alias /statics /home/lbi/rdfweb/web/lbirdf/statics
Alias /admin_media /home/lbi/rdfweb/web/lbirdf/admin_media
<Directory /home/lbi/rdfweb/web/lbirdf/apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/lbi/rdfweb/web/lbirdf/admin_media>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Any ideas on where I might be going wrong?
What messages are in the Apache error log? Try setting DEBUG to true in Django settings file to get more informative error message sent back to browser in instance that it is an issue in your application.
Possible causes are, urls.py is wrong because you are erroneously including site prefix when you don't need to or a permissions issue because code running as Apache user and not you.
Not knowing the actual errors doesn't help in working out the problem.
Try:
sys.path.append('/home/lbi/rdfweb/')