Python's working directory when running with WSGI and Apache

You should not change working directory.

Use:

import os
here = os.path.dirname(__file__)

The variable here will then contain the directory where that code file is located. You can then construct absolute paths for things relative to that.

database = os.path.join(here, 'database.db')

Do note that the user your code runs under in Apache still needs read/write access to that directory.

As always, make sure you read the documentation. Relevant sections of documentation are:

  • Application Working Directory
  • Access Rights of Apache User