--- a/seahub/settings.py
+++ b/seahub/settings.py
@@ -140,7 +140,7 @@ TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
         'DIRS': [
-            os.path.join(PROJECT_ROOT, '../../seahub-data/custom/templates'),
+            os.path.join(os.environ.get('SEAFILE_UCI_DATA_DIR', os.path.join(PROJECT_ROOT, '../..')), 'seahub-data/custom/templates'),
             os.path.join(PROJECT_ROOT, 'seahub/templates'),
         ],
         'APP_DIRS': True,
@@ -646,7 +646,7 @@ CAPTCHA_IMAGE_SIZE = (90, 42)
 ENABLE_THUMBNAIL = True
 
 # Absolute filesystem path to the directory that will hold thumbnail files.
-SEAHUB_DATA_ROOT = os.path.join(PROJECT_ROOT, '../../seahub-data')
+SEAHUB_DATA_ROOT = os.path.join(os.environ.get('SEAFILE_UCI_DATA_DIR', os.path.join(PROJECT_ROOT, '../..')), 'seahub-data')
 if os.path.exists(SEAHUB_DATA_ROOT):
     THUMBNAIL_ROOT = os.path.join(SEAHUB_DATA_ROOT, 'thumbnail')
 else:
@@ -842,7 +842,7 @@ except ImportError:
     pass
 else:
     # In server release, sqlite3 db file is <topdir>/seahub.db
-    DATABASES['default']['NAME'] = os.path.join(install_topdir, 'seahub.db')
+    DATABASES['default']['NAME'] = os.path.join(os.environ.get('SEAFILE_UCI_DATA_DIR', install_topdir), 'seahub.db')
 
     # In server release, gunicorn is used to deploy seahub
     INSTALLED_APPS += ('gunicorn', )
