I am deploying a django project in production using ubuntu, and I have been following this tutorial explaining how to setup and run mod_wsgi in production. Upon running apachectl start I get the following error
apachectl start
AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/django_project-le-ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/www.dimsum.dk/fullchain.pem' does not exist or is empty
Action 'start' failed.
The Apache error log may have more information.
Prior starting the apachectl I did the followings:
pip install mod_wsgi
The installation was successful and I then put mod_wsgi.server in my INSTALLED_APPS under settings.py. I then run without problem
python manage.py runmodwsgi \
--server-root/etc/wsgi-port-80 \
--user www-data --group www-data \
--port 80 --setup-only
Then I stopped my current apache2 server by
sudo service apache2 stop
Followed by
/etc/wsgi-port-80/apachectl start
and got the error
AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/django_project-le-ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/www.dimsum.dk/fullchain.pem' does not exist or is empty
Action 'start' failed.
The Apache error log may have more information.
When running with sudo the problem is solved.
Related
I am trying to deploy my very first Django applicatin on heroku. Gunicorn gives me this error: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
In this answer https://stackoverflow.com/a/55623889 command gunicorn app:application --preload -b 0.0.0.0:5000 is said to give detailed error message, but as its comments state it is not clear what words to replace with what. For instance somewhere I saw something similar called with <name of my app>.wsgi. To make matter worse name of my Django app in local is different from the one on Heroku.
Also it is not clear to me should this be called strait from terminal (within virtual env) or should I be using some sort of gunicorn CLI.
So what is the actual propper way to figure out what is failing gunicorn?
I've faced similar issues in the past. I hope this might help:
Make sure gunicorn is installed in your activated virtual environment project by running pip freeze in the terminal to verify it's installation. If it is not listed, in the activated virtual environment, run pip install gunicorn or else if you are using pipenv, run pipenv install gunicorn. Don't forget to update the requirements.txt file by running pip freeze > requirements.txt
In the Procfile which is within the project_directory type the syntax:
web: gunicorn your_django_project_name.wsgi --log-file -
N.B: There should be a space between;
The --log-file and the - next to it.
web: and the gunicorn part of the code.
Finally add, commit and push the changes to the heroku server.
I just tried to install the django-debug-toolbar. I believe I followed all the steps as indicated in the docs. I am using docker, so I included the following in my settings:
if os.environ.get('DEBUG'):
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
After installing, I ran docker-compose build then docker-compose up -d. docker-compose logs and docker-compose exec web python manage.py collectstatic show the error
ModuleNotFoundError: No module named 'debug-toolbar'
The only thing I think I did differently from the docs is that I use pipenv. I exited docker-compose and then installed via pipenv install django-debug-toolbar. Debug toolbar is in my pipfile.
I'm never sure if I'm supposed to exit docker-compose before install a module via pipenv (or if it matters). I also tried installed via docker-compose exec web pipenv install django-debug-toolbar, shut down the container, then docker-compose up -d --build but the module not found error is still there.
Typo error on my part. In settings.py under installed apps I had debug-toolbar instead of debug_toolbar.
I had started a fresh linode running ubuntu 19.04 and the first time I used the directions at:
https://www.rosehosting.com/blog/how-to-install-mezzanine-cms-on-ubuntu-18-04/
To install Mezzanine CMS it worked just fine, I could run the runserver command and see the django website. Eventually it started giving me a problem after trying 50 ways to deploy the site using apache and mod_wsgi.
I gave up and rebuilt the server and then still couldn't see the new install at the IP when I ran run server. I figured maybe it was because I accidentally installed some things using "python" and others with "python3" so I rebuilt the server.
This third time I followed the direction perfectly, the only difference is I didn't install a mysql server just kept the default SQLlite server and created a DB and Django Superuser.
I have added my ip as a host in settings.py and local_settings.py
I have already ran makemigrations and migrate
I did check to see if maybe the IP had changed when I rebuilt, it hadn't
My local environment on my laptop works fine, just not the linode
Any suggestions on anything I'm missing?
Deployment Guide
Step 1 (Installation)
Install apache2 mod_wsgi
Install virtualenv
Install virtualenv
Install Nginx for asynchronous event-driven approach to handle multiple client requests
Install mysql
sudo apt-get update
sudo apt-get install python3-pip python3-dev apache2 libapache2-mod-wsgi-py3
sudo apt-get install virtualenv ufw
sudo apt-get install nginx
sudo apt-get install mysql-server libmysqlclient-dev
sudo mysql_secure_installation
Step 2 (Apache & Hostname & User)
Set hostname and add it into /etc/hosts with hostname and your Server IP
Create new user and give add to the group sudo for safety
sudo adduser username
sudo usermod -aG sudo
Enable SSH authentication for login & Edit default port of ssh in /etc/ssh/sshd_config. https://askubuntu.com/questions/1074034/not-able-to-change-ssh-port-on-ubuntu-18-04-1-lts
Edit /etc/apache2/site-availabledefault-000.conf for your new Django configuration
Step 3 (Firewall)
sudo ufw allow 8000
sudo ufw allow http
sudo ufw allow ssh
sudo ufw default allow outgoing
sudo ufw default deny incoming
Enable all other required port numbers
ssh sudo ufw enable
Step 4 (Django configuration)
Chown static and media forlders and edit it's permission recursively
Add allowed host in settings.py
Checkout deployment checklist in django official website and do it.
Step 5 (Please checkout)
For apache configuration please visit https://pythonprogramming.net/deploying-to-server-django-tutorial/
Edit the path given in your apache configuration (path for WSGI Script,python-path, python-home ) if any errors found like Internal server error, miss configuration etc
For reference of python-home path please refer Get virtualenv's bin folder path from script
You can also add python-path to WSGIDaemonProcess
Additionally, you can visit puttygen for public and private key generation to login through SSH
For this particular problem turned out I just needed to suddenly bind dev server to 0.0.0.0
the command to do so was
python manage.py runserver 0.0.0.0:8000
Rinshans answers is definetley the details for deployment, I've followed those steps just kept making some mistake in the config and wsgi scripts. I'm going to try deploying with Gunicorn or use the Fabric self-deployment tools built in to Mezzanine CMS, just haven't done so yet.
I want to deploy a very basic Django app on Heroku. I followed the instructions, but the browser shows me the Heroku error page and the heroku logs say
bash: gunicorn: command not found
I have gunicorn in my requirements.txt and configured the wsgi.py and Procfile as instructed by the documentation. What else can I try?
Edit: I also tried to install gunicorn manually on Heroku (heroku run pip install gunicorn), which worked fine, so I am pretty sure that gunicorn is installed. Why doesn't Heroku find it?
Edit 2: It seems that I can install gunicorn manually (heroku run bash and then pip install gunicorn:
~ $ gunicorn
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.
but when i log out and log in to the bash again, i get:
~ $ gunicorn
bash: gunicorn: command not found
Heroku seems to install but then discard gunicorn. How can that be?
Hi got the same problem but this might help:
Go to this:
https://github.com/heroku/heroku-buildpack-python
And try to run this command in project's root terminal:
heroku buildpacks:set git://github.com/heroku/heroku-buildpack-python.git
and then update heroku with running below command:
git push heroku master
I'm trying to install gunicorn in my virtual env, but get the following:
$ pip install gunicorn
Downloading/unpacking gunicorn
Downloading gunicorn-0.14.2.tar.gz (203Kb): 203Kb downloaded
Running setup.py egg_info for package gunicorn
warning: no files found matching '*' under directory 'debian'
Installing collected packages: gunicorn Found existing installation: gunicorn 0.14.2
Uninstalling gunicorn:
Successfully uninstalled gunicorn
Running setup.py install for gunicorn
warning: no files found matching '*' under directory 'debian'
Installing gunicorn_paster script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn script to /home/aemdy/Documents/projects/reborn/env/bin
Installing gunicorn_django script to /home/aemdy/Documents/projects/reborn/env/bin
Successfully installed gunicorn
Cleaning up...
And when I use python manage.py run_gunicorn for django it says that this is unknown command. I have added gunicorn to INSTALLED_APPS.
Warnings like that appear sometimes when installing apps. I believe it's related to cleanup pip tries to do, but it doesn't matter regardless. As the console output says "Successfully installed gunicorn". So no problems there.
With gunicorn installed, the only other requirement is adding gunicorn to INSTALLED_APPS. If you've done that as well, you're done. run_gunicorn will be available.
So, if it's not working, one of the following is in play:
Gunicorn isn't actually installed. However, you should get an error trying to reference in in INSTALLED_APPS in that scenario. Check your virtualenv's site-packages directory to ensure there's gunicorn folder there.
You installed Gunicorn in a different virtualenv. Again, you should be getting an error just as in #1. And, just as in #1, check to make sure it's actually in the proper virtualenv's site-packages directory
You don't have the virtualenv activated. However, same error as in #1 and #2 applies here.
You really don't have gunicorn in INSTALLED_APPS or a compiled version of settings.py is being used that doesn't have it in INSTALLED_APPS. Delete settings.pyc if it exists.
I just ran into this issue. What I did was try to run the app using runserver which led to me seeing the hostname on the server was not set(and thus can't get an IP address). Once we fixed that issue the command worked again.
It is a little misleading to see:
Unknown command: 'run_gunicorn'
Type 'manage.py help' for usage.
when the hostname is not set...confusing I know but I hope this helps someone in the future.
Did you remember to add gunicorn to your INSTALLED_APPS?