0

I'm trying to deploy a django application in a VPS running ubuntu 20.04.

I settings.py

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
  'OPTIONS': {
  'read_default_file':'/home/ubuntu/arainc/auth/mysql.cnf'
  },
 }
}

And the configuration file:

#mysql.cnf
[client]
database = 'dbname'
user = 'dbuser'
password = 'dbuser@123'
default-character-set = 'utf8'

While trying to reach the site, I get the below error:

Environment:


Request Method: GET
Request URL: http://208.115.109.194/

Django Version: 3.0.7
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'araincdb',
 'import_export',
 'crispy_forms',
 'django_filters',
 'widget_tweaks']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 199, in _get_session
    return self._session_cache

During handling of the above exception ('SessionStore' object has no attribute '_session_cache'), another exception occurred:
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
    return Database.connect(**conn_params)
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/home/ubuntu/arainc/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)

Exception Type: OperationalError at /
Exception Value: (1045, "Access denied for user 'www-data'@'localhost' (using password: NO)")

I can login to the database with the credentials in the configuration file.

How can I solve this? Any help would be much appreciated.

Lone Rider
  • 97
  • 2
  • 10

1 Answers1

0

my.cnf file was world-writable.

I changed the file permission of the configuration file to read-only by applying the following chmod command.

Make cnf files read only

chmod 0444 my.cnf

Lone Rider
  • 97
  • 2
  • 10