Deploying with apache2 and modwsgi

36 views
Skip to first unread message

Joel Mathew

unread,
Aug 29, 2018, 7:21:01 AM8/29/18
to django...@googlegroups.com
After working with the development server for a month, I'm ready to
deploy to a VPS.
I've installed a debian9 environment and installed apache2 and
modwsgi. I'm having trouble editing the httpd.conf and apache wont
start with the added lines.

My project is at /home/joel/myappointments and the tree looks like this:
root@localhost:/home/joel/myappointments# tree -L 2
.
├── appointments
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations
│ ├── models.py
│ ├── __pycache__
│ ├── static
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ ├── using shell.txt
│ └── views.py
├── bugs.txt
├── db.sqlite3
├── django-todo.txt
├── manage.py
├── myappointments
│ ├── __init__.py
│ ├── middleware.py
│ ├── __pycache__
│ ├── settings.py
│ ├── settings.py~
│ ├── urls.py
│ └── wsgi.py
├── notebook.tex
├── propellor
│ ├── button.css
│ ├── floating-action-button.css
│ ├── materialicons.css
│ └── typography.css
├── README.md
├── requirements.txt
├── requirements.txt~
└── venv
├── bin
├── include
├── lib
└── pip-selfcheck.json

My apache conf is /home/joel/myappointments# cat
/etc/apache2/sites-enabled/000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

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

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

WSGIScriptAlias / /home/joel/myappointments/myappointments/wsgi.py
WSGIPythonHome /home/joel/myappointments/venv
WSGIPythonPath /home/joel/myappointments

<Directory /home/joel/myappointments>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Can you tell me how to modify my apache conf file?

Jason

unread,
Aug 29, 2018, 7:42:30 AM8/29/18
to Django users
just to cnfirm, are you using mod_wsgi3 for python3?  

and what do you get when you run apachectl configtest

Joel Mathew

unread,
Aug 29, 2018, 9:36:20 AM8/29/18
to django...@googlegroups.com
I get this:

Aug 29 12:24:52 localhost systemd[1]: Starting The Apache HTTP Server...
Aug 29 12:24:52 localhost apachectl[12718]: AH00526: Syntax error on
line 31 of /etc/apache2/sites-enabled/000-default.conf:
Aug 29 12:24:52 localhost apachectl[12718]: WSGIPythonHome cannot
occur within <VirtualHost> section
Aug 29 12:24:52 localhost apachectl[12718]: Action 'start' failed.
Aug 29 12:24:52 localhost apachectl[12718]: The Apache error log may
have more information.
Aug 29 12:24:52 localhost systemd[1]: apache2.service: Control process
exited, code=exited status=1
Aug 29 12:24:52 localhost systemd[1]: Failed to start The Apache HTTP Server.
Aug 29 12:24:52 localhost systemd[1]: apache2.service: Unit entered
failed state.
Aug 29 12:24:52 localhost systemd[1]: apache2.service: Failed with
result 'exit-code'.

On Wed, 29 Aug 2018 at 17:12, Jason <jjohn...@gmail.com> wrote:
>
> just to cnfirm, are you using mod_wsgi3 for python3?
>
> and what do you get when you run apachectl configtest
>
> --
> 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/f290afe5-bd7c-467c-890b-e0faef16ad03%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jason

unread,
Aug 29, 2018, 9:47:18 AM8/29/18
to Django users
well, that's self-explainatory.  you have a bad config because that WSGIPythonHome directive can't exist inside a VirtualHost section.

Joel Mathew

unread,
Aug 29, 2018, 9:50:31 AM8/29/18
to django...@googlegroups.com
I surmised as much. But where does it go? Do you have a full working
configuration of the conf file?
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f2d7bed-9eb4-4bfa-bdee-5e1e5c52f6a6%40googlegroups.com.

Joel Mathew

unread,
Aug 30, 2018, 6:50:24 AM8/30/18
to django...@googlegroups.com
I finally got it working with mod_wsgi-express. I was able to get my
django project running on port 80.
However I have a new problem. The page starts loading, but takes a
very long time to load static files. If I hit refresh in the browser,
it gives a 503 error. There's nothing in apache logs. The
mod_wsgi-express page says there's a log file created in server root.
However I was unable to find it to trace the issue.
On another note, is this the right place to ask these doubts regarding
deploying django on the server? Or is there a better usergroup?
Reply all
Reply to author
Forward
0 new messages