I am trying to Django with MS SQL Server on CentOS 7 using Apache mod_wsgi. I'm able to run the Django app using python manage.py runserver 0.0.0.0:8000
and navigate to my grappeli admin page.
However, when I run using Apache, the home site loads up just fine but then I get OperationalError: ('HYT00', u'[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
when I attempt to navigate to the admin page.
It's strange that runserver would work using the same virtualenv that I'm pointing my apache config at.
pip freeze:
Django==1.11.10
django-grappelli==2.10.2
django-pyodbc==1.1.3
django-pyodbc-azure==1.11.9.0
pymssql==2.1.3
pyodbc==4.0.22
contents of /etc/httpd/conf.d/django.conf:
<Directory /opt/measurement_app/measurement_app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess measurement_app python-path=/opt/measurement_app:/opt/measurement_app/measurementenv/lib/python2.7/site-packages
WSGIProcessGroup measurement_app
WSGIScriptAlias / /opt/measurement_app/measurement_app/wsgi.py
settings.py:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'MEASUREMENT',
'HOST': ****,
'PORT': 1433,
'USER': ****,
'PASSWORD': *****,
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
'dsn': 'app-sqldb',
'use_legacy_datetime': True,
}
}
}
odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-17.0.so.1.1
UsageCount=1
odbc.ini
[app-sqldb]
Driver = ODBC Driver 17 for SQL Server
Description = SQL Server 2012 DenSQL
Server = ****
instance = MEASUREMENT
Database = MEASUREMENT
Port = 1433
Trace = Yes
TraceFile = /tmp/odbc.log
So the problem was that my SELinux configuration was restrictive and was blocking the connection. The solution was to edit my
/etc/selinux/config
and setthen
reboot
The mod_wsgi documentation mentions that SELinux has the potential to cause some issues in: