Trouble deploying Django/wagtail on Ubuntu 14.04

76 views
Skip to first unread message

drone4four

unread,
Mar 20, 2018, 12:09:10 AM3/20/18
to Django users
I successfully installed wagtail’s bakery demo site locally.  I ended up leveraging the README for this bakery demo site on their GitHub page which calls to use a ‘virtualenvwrapper’ instead of a typical venv.  As instructed I played around with some configuration files. I got it working. Here is a .webm video showcasing my site running locally.  

But when I attempt to deploy it on my DigitalOcean Droplet, Apache is throwing all sorts of errors.  The problem is with my configuration. I am not sure what I have to change to make it right. 

Here is my site showing an Apache Internal Server Error: https://daniel496.agency/ 

Here are the most recent lines of traceback from my Apache log file. That log file is pointing me in a few directions. I ensure that my Apache sites-available file points to wsgi.py inside the bakerydemo project folder.  I tried both wsgi.py and production_wsgi.py.

Here are the contents of my ssl Apache sites-available ssl config:
<IfModule mod_ssl.c>
<VirtualHost *:443>


        ServerAdmin
<user>@gmail.com
        ServerName daniel496.agency
        ServerAlias www.daniel496.agency
#       DocumentRoot /var/www/html/daniel496.agency/public_html


#       ErrorLog ${APACHE_LOG_DIR}/error.log
        ErrorLog ${APACHE_LOG_DIR}/daniel496/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


        # Original Django project commented out 19 March 2018 to make room for Django project below
       
<IfDefine IgnoreBlockComment>
        Alias /static /home/
<user>/TheGreatWork/static
        <Directory /home/
<user>/TheGreatWork/static>
                Require all granted
       
</Directory>


        <Directory /home/
<user>/TheGreatWork/TheGreatWork>
               
<Files wsgi.py>
                    Require all granted
               
</Files>
       
</Directory>


        WSGIDaemonProcess TheGreatWork python-home=/home/
<user>/TheGreatWork/venv
        WSGIProcessGroup TheGreatWork
        WSGIScriptAlias / /home/
<user>/TheGreatWork/TheGreatWork/wsgi.py


       
</IfDefine>




        # 2nd Django project (wagtail demo)
        Alias /static /home/
<user>/bakerydemo/bakerydemo/static
        <Directory /home/
<user>/bakerydemo/bakerydemo/static>
                Require all granted
       
</Directory>


        <Directory /home/
<user>/bakerydemo/bakerydemo>
               
<Files wsgi.py>
                    Require all granted
               
</Files>
       
</Directory>


        WSGIDaemonProcess bakerydemo python-home=/home/
<user>/.virtualenvs/wagtailbakerydemo/
        WSGIProcessGroup bakerydemo
        WSGIScriptAlias / /home/
<user>/bakerydemo/bakerydemo/wsgi.py


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/daniel496.agency/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/daniel496.agency/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/daniel496.agency/chain.pem


</VirtualHost>
</IfModule>


Take note the project called, TheGreatWork.  That is a previous project I've temporarily set aside.  I invoked a multi-line block comment in this Apache starting with <IfDefine IgnoreBlockComment> and ending with </IfDefine>

As part of setting up virtualenvwrapper, I’ve assigned my virtual environments to: /home/<user>/.virtualenvs, which appears to be an issue in the error log as well, so maybe this could be the problem with my setup?

I’ve ruled out the possibility that the issue has something to do with the Python version 2.7-based libapache2-mod-wsgi because I purged my system of that library. All that exists now is libapache2-mod-wsgi-py3.

I'm running Ubuntu 14.04 on my Droplet, running Python 3.4 and Django 2.0.

Is there any other information I could provide to help troubleshoot?

Thanks for your attention.

Cictani

unread,
Mar 20, 2018, 5:45:27 AM3/20/18
to Django users
You have to set the python-path too:

WSGIDaemonProcess bakerydemo python-home=/home/<user>/.virtualenvs/wagtailbakerydemo/ python-path=/home/<user>/bakerydemo/

In the logs you see "
No module named 'bakerydemo'" because you did not add the project directory to the python-path. Hope this works.

Best regards

Andreas

drone4four

unread,
Mar 20, 2018, 12:14:08 PM3/20/18
to Django users
Thank you, Andreas.  I added the python-path to my Apache ssl.conf and the Internal Server Error is gone now. It appears WSGI is serving my Django project perfectly. 

I adjusted ALLOWED_HOSTS just fine. But now Django is saying something about "TemplateDoesNotExist at /" in base/home_page.html.  You can see the full Django traceback here: https://daniel496.agency/ 

$ locate home_page.html
/home/<user>/.virtualenvs/wagtailbakerydemo/lib/python3.4/site-packages/wagtail/project_template/home/templates/home/home_page.html
/home/<user>/bakerydemo/bakerydemo/templates/base/home_page.html

The home_page.html file is present but apparently it is not being referred to properly in my configuration.  Can anyone shed some light on what the issue could be now?

Thanks.

Tom Evans

unread,
Mar 20, 2018, 2:49:59 PM3/20/18
to django...@googlegroups.com
It is not looking for "home_page.html", it is looking for
"base/home_page.html". On the error page it lists the locations it is
searching for the template, and explicitly says the directories that
are being searched.

You say the file is at
/home/<user>/bakerydemo/bakerydemo/templates/base/home_page.html

It says it is looking in /var/www/bakerydemo/templates/

This means that your TEMPLATES['DIRS'] setting is wrong.

Looking at the configuration section of the error report shows that
you have put a relative path into TEMPLATE['DIRS']. Use
settings.PROJECT_ROOT to make that in to an absolute path, as the
example settings.py tells you to do.

Cheers

Tom

PS - there is very little point anonymising your username when you
share the full error report.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d90b8924-5458-4c0e-8f0f-2866af4dd156%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

drone4four

unread,
Apr 3, 2018, 9:33:48 PM4/3/18
to Django users

Thank you for your reply, Tom.


Here it is running as intended: https://daniel496.agency/


Inside the TEMPLATES variable, the line for ‘DIRS’ now a list which now reads: [PROJECT_ROOT + '/bakerydemo/templates']


    'DIRS': [PROJECT_ROOT + '/bakerydemo/templates'],


M project root directory is /home/tranq/bakerydemo and the addition symbol binds the subsequent string together to create a new string as it is read by the interpreter: '/home/<user>/bakerydemo/bakerydemo/templates'


I also had to toy around a bit with group and ownership permissions.  Here are the winning commands I used in the end:


$ chmod 775 /home/tranq/bakerydemo
$ chown :www-data /home/tranq/bakerydemo
$ chmod 775 /home/tranq/bakerydemo/bakerydemodb
$ chown :www-data /home/tranq/bakerydemo/bakerydemodb
$ chown -R :www-data /home/tranq/bakerydemo/bakerydemo/media
 

I had this demo running perfectly weeks ago. I meant to report back here like this sooner. Sorry.  Better late than never?


Thanks again.
Reply all
Reply to author
Forward
0 new messages