matomo-org / plugin-EnvironmentVariables

Allows you to specify Matomo config in environment variables instead of the config file.
12 stars 14 forks source link

Plugin does not work if config/config.ini.php is present #2

Closed toredash closed 5 years ago

toredash commented 5 years ago

The plugin does not work if the config/config.ini.php-file is present.

#  curl -v localhost:8000 2>&1 | grep HTTP
> GET / HTTP/1.1
< HTTP/1.1 500 Internal Server Error
# rm config.ini.php
#  curl -v localhost:8000 2>&1 | grep HTTP
> GET / HTTP/1.1
< HTTP/1.1 200 OK

The error I get is: Cache backend %%MATOMO_CACHE_BACKEND%% not valid. Log file with log-level DEBUG shows:

==> ../tmp/%%MATOMO_HOSTNAME%%/logs/piwik.log <==
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] /var/www/libs/Zend/Db/Adapter/Pdo/Abstract.php(144): SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #0 /var/www/libs/Zend/Db/Adapter/Pdo/Mysql.php(109): Zend_Db_Adapter_Pdo_Abstract->_connect()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #1 /var/www/core/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Mysql->_connect()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #2 /var/www/core/Db/Adapter/Pdo/Mysql.php(74): Piwik\Db\Adapter\Pdo\Mysql->_connect()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #3 /var/www/core/Db/Adapter.php(51): Piwik\Db\Adapter\Pdo\Mysql->getConnection()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #4 /var/www/core/Db.php(122): Piwik\Db\Adapter::factory('PDO\\MYSQL', Array)
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #5 /var/www/core/Db.php(54): Piwik\Db::createDatabaseObject()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #6 /var/www/core/Db.php(725): Piwik\Db::get()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #7 /var/www/core/Db.php(221): Piwik\Db::logExtraInfoIfDeadlock(Object(Zend_Db_Adapter_Exception))
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #8 /var/www/core/Option.php(271): Piwik\Db::fetchAll('SELECT option_v...')
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #9 /var/www/core/Option.php(173): Piwik\Option->autoload()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #10 /var/www/core/Option.php(46): Piwik\Option->getValue('branding_use_cu...')
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #11 /var/www/plugins/CoreAdminHome/CustomLogo.php(51): Piwik\Option::get('branding_use_cu...')
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #12 /var/www/plugins/CoreAdminHome/CustomLogo.php(66): Piwik\Plugins\CoreAdminHome\CustomLogo->isEnabled()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #13 /var/www/core/ExceptionHandler.php(107): Piwik\Plugins\CoreAdminHome\CustomLogo->hasSVGLogo()
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #14 /var/www/core/ExceptionHandler.php(71): Piwik\ExceptionHandler::getErrorResponse(Object(Piwik\Cache\Backend\Factory\BackendNotFoundException))
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #15 /var/www/core/ExceptionHandler.php(36): Piwik\ExceptionHandler::dieWithHtmlErrorPage(Object(Piwik\Cache\Backend\Factory\BackendNotFoundException))
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #16 [internal function]: Piwik\ExceptionHandler::handleException(Object(Piwik\Cache\Backend\Factory\BackendNotFoundException))
DEBUG Piwik\ExceptionHandler[2019-03-21 14:05:27 UTC] [b8cff] #17 {main}

The funny thing is that if I execute index.php directly via php7 index.php the same log file shows no errors at all: DEBUG Piwik\Plugin\Manager[2019-03-21 14:05:48 UTC] [902] Loaded plugins: CorePluginsAdmin, CoreAdminHome, CoreHome, WebsiteMeasurable, IntranetMeasurable, Diagnostics, CoreVisualizations, Proxy, API, ExamplePlugin, Widgetize, Transitions, LanguagesManager, Actions, Dashboard, MultiSites, Referrers, UserLanguage, DevicesDetection, Goals, Ecommerce, SEO, Events, UserCountry, GeoIp2, VisitsSummary, VisitFrequency, VisitTime, VisitorInterest, ExampleAPI, RssWidget, Feedback, Monolog, Login, TwoFactorAuth, UsersManager, SitesManager, Installation, CoreUpdater, CoreConsole, ScheduledReports, UserCountryMap, Live, CustomVariables, PrivacyManager, ImageGraph, Annotations, MobileMessaging, Overlay, SegmentEditor, Insights, Morpheus, Contents, BulkTracking, Resolution, DevicePlugins, Heartbeat, Intl, Marketplace, ProfessionalServices, UserId, CustomPiwikJs, DBStats, CustomDimensions, CustomReports, EnvironmentVariables, InvalidateReports, QueuedTracking, TasksTimetable

My ENV variables are as such (X used as replacement value for sensitive information):

MATOMO_CACHE_BACKEND=redis
MATOMO_DATABASE_DBNAME=matomo
MATOMO_DATABASE_HOST=Xamazonaws.com
MATOMO_DATABASE_PASSWORD=X
MATOMO_DATABASE_USERNAME=master
MATOMO_DEBUG_ENABLE_SQL_PROFILER=0
MATOMO_ENABLE_INSTALLER=0
MATOMO_GENERAL_ASSUME_SECURE_PROTOCOL=1
MATOMO_GENERAL_ENABLE_INSTALLER=0
MATOMO_GENERAL_FORCE_SSL=1
MATOMO_GENERAL_INSTANCE_ID=X
MATOMO_GENERAL_LIVE_WIDGET_REFRESH_AFTER_SECONDS=10
MATOMO_GENERAL_LIVE_WIDGET_VISITOR_COUNT_LAST_MINUTES=15
MATOMO_GENERAL_LOG_LEVEL=INFO
MATOMO_GENERAL_MAINTENANCE_MODE=0 
MATOMO_GENERAL_SALT=X
MATOMO_HOSTNAME=X
MATOMO_LOG_LEVEL=INFO
MATOMO_QUEUEDTRACKING_BACKEND=redis
MATOMO_QUEUEDTRACKING_NUMQUEUEWORKERS=8
MATOMO_QUEUEDTRACKING_NUMREQUESTSTOPROCESS=15
MATOMO_QUEUEDTRACKING_QUEUEENABLED=true
MATOMO_QUEUEDTRACKING_REDISDATABASE=2
MATOMO_QUEUEDTRACKING_REDISHOST=Xamazonaws.com
MATOMO_QUEUEDTRACKING_USESENTINELBACKEND=false
MATOMO_REDISCACHE_DATABASE=0
MATOMO_REDISCACHE_HOST=Xamazonaws.com
MATOMO_SALT=X
MATOMO_TRACKER_HOSTNAME=X
MATOMO_VERSION=3.8.1

Full content of config.ini.php:

; <?php exit; ?> DO NOT REMOVE THIS LINE
; file automatically generated or modified by Matomo; you can manually override the default values in global.ini.php by redefining them in this file.
[database]
host = "%%DBHOST%%"
username = "%%MYSQL_USER%%"
password = "%%MYSQL_PASSWORD%%"
dbname = "%%MYSQL_DBNAME%%"
tables_prefix = "matomo_"

[General]
salt = "%%MATOMO_SALT%%"
trusted_hosts[] = "%%MATOMO_HOSTNAME%%"
trusted_hosts[] = "%%MATOMO_TRACKER_HOSTNAME%%"

;TODO: Fix
cors_domains[] = *

; disable browser trigger archiving for all requests (even those with a segment)
browser_archiving_disabled_enforce = 0

multi_server_environment = 1

; when set to 1, all requests to Matomo will return a maintenance message without connecting to the DB
; this is useful when upgrading using the shell command, to prevent other users from accessing the UI while Upgrade is in progress
maintenance_mode = %%MATOMO_MAINTENANCE_MODE%%

; by default, the real time Live! widget will update every 5 seconds and refresh with new visits/actions/etc.
; you can change the timeout so the widget refreshes more often, or not as frequently
live_widget_refresh_after_seconds = 10

; by default, the Live! real time visitor count widget will check to see how many visitors your
; website received in the last 3 minutes. changing this value will change the number of minutes
; the widget looks in.
live_widget_visitor_count_last_minutes = 5

; In "All Websites" dashboard, when looking at today's reports (or a date range including today),
; the page will automatically refresh every 5 minutes. Set to 0 to disable automatic refresh
multisites_refresh_after_seconds = 0

; If set to 1, Matomo will automatically redirect all http:// requests to https://
; If SSL / https is not correctly configured on the server, this will break Matomo
; If you set this to 1, and your SSL configuration breaks later on, you can always edit this back to 0
; it is recommended for security reasons to always use Matomo over https
force_ssl = 1
assume_secure_protocol = 1

; by default, an update notification for a new version of Matomo is shown to every user. Set to 1 if only
; the superusers should see the notification.
show_update_notification_to_superusers_only = 1

; Uncomment line below if you use a standard proxy
proxy_client_headers[] = HTTP_X_FORWARDED_FOR
proxy_host_headers[] = HTTP_X_FORWARDED_HOST

; In some rare cases it may be useful to explicitely tell Matomo not to use LOAD DATA INFILE
; This may for example be useful when doing Mysql AWS replication
enable_load_data_infile = 1

; by default, Matomo uses PHP's built-in file-based session save handler with lock files.
; For clusters, use dbtable.
; We did use redis, but not supported since 3.8.0
session_save_handler = dbtable

; If set to 0 it will disable advertisements for providers of Professional Support for Matomo.
piwik_professional_support_ads_enabled = 0

; By setting this option to 0, it will disable the "Auto update" feature
enable_auto_update = 0

; By setting this option to 0 (e.g. in common.config.ini.php) the installer will be disabled.
enable_installer = %%MATOMO_ENABLE_INSTALLER%%

; By setting this option to 0:
; - links to Enable/Disable/Uninstall plugins will be hidden and disabled
; - links to Uninstall themes will be disabled (but user can still enable/disable themes)
enable_plugins_admin = 0

; By setting this option to 1, it will be possible for Super Users to upload Matomo plugin ZIP archives directly in Matomo Administration.
; Enabling this opens a remote code execution vulnerability where
; an attacker who gained Super User access could execute custom PHP code in a Matomo plugin.
enable_plugin_upload = 0

; By default we check whether the Custom logo is writable or not, before we display the Custom logo file uploader
enable_custom_logo_check = 0

; If you use this Matomo instance over multiple hostnames, Matomo will need to know
; a unique instance_id for this instance, so that Matomo can serve the right custom logo and tmp/* assets,
; independently of the hostname Matomo is currently running under.
instance_id = %%MATOMO_HOSTNAME%%

[log]
; possible values for log: screen, database, file
log_writers[] = screen

; log level, everything logged w/ this level or one of greater severity
; will be logged. everything else will be ignored. possible values are:
; ERROR, WARN, INFO, DEBUG
log_level = %%MATOMO_LOG_LEVEL%%

[Plugins]
Plugins[] = "CorePluginsAdmin"
Plugins[] = "CoreAdminHome"
Plugins[] = "CoreHome"
Plugins[] = "WebsiteMeasurable"
Plugins[] = "IntranetMeasurable"
Plugins[] = "Diagnostics"
Plugins[] = "CoreVisualizations"
Plugins[] = "Proxy"
Plugins[] = "API"
Plugins[] = "ExamplePlugin"
Plugins[] = "Widgetize"
Plugins[] = "Transitions"
Plugins[] = "LanguagesManager"
Plugins[] = "Actions"
Plugins[] = "Dashboard"
Plugins[] = "MultiSites"
Plugins[] = "Referrers"
Plugins[] = "UserLanguage"
Plugins[] = "DevicesDetection"
Plugins[] = "Goals"
Plugins[] = "Ecommerce"
Plugins[] = "SEO"
Plugins[] = "Events"
Plugins[] = "UserCountry"
Plugins[] = "GeoIp2"
Plugins[] = "VisitsSummary"
Plugins[] = "VisitFrequency"
Plugins[] = "VisitTime"
Plugins[] = "VisitorInterest"
Plugins[] = "ExampleAPI"
Plugins[] = "RssWidget"
Plugins[] = "Feedback"
Plugins[] = "Monolog"
Plugins[] = "Login"
Plugins[] = TwoFactorAuth
Plugins[] = "UsersManager"
Plugins[] = "SitesManager"
Plugins[] = "Installation"
Plugins[] = "CoreUpdater"
Plugins[] = "CoreConsole"
Plugins[] = "ScheduledReports"
Plugins[] = "UserCountryMap"
Plugins[] = "Live"
Plugins[] = "CustomVariables"
Plugins[] = "PrivacyManager"
Plugins[] = "ImageGraph"
Plugins[] = "Annotations"
Plugins[] = "MobileMessaging"
Plugins[] = "Overlay"
Plugins[] = "SegmentEditor"
Plugins[] = "Insights"
Plugins[] = "Morpheus"
Plugins[] = "Contents"
Plugins[] = "BulkTracking"
Plugins[] = "Resolution"
Plugins[] = "DevicePlugins"
Plugins[] = "Heartbeat"
Plugins[] = "Intl"
Plugins[] = "Marketplace"
Plugins[] = "ProfessionalServices"
Plugins[] = "UserId"
Plugins[] = "CustomPiwikJs"
Plugins[] = "QueuedTracking"
Plugins[] = "DBStats"
Plugins[] = "TasksTimetable"
Plugins[] = "CustomDimensions"
Plugins[] = "CustomReports"
Plugins[] = "InvalidateReports"
Plugins[] = "EnvironmentVariables"

[PluginsInstalled]
PluginsInstalled[] = "Diagnostics"
PluginsInstalled[] = "Login"
PluginsInstalled[] = TwoFactorAuth
PluginsInstalled[] = "CoreAdminHome"
PluginsInstalled[] = "UsersManager"
PluginsInstalled[] = "SitesManager"
PluginsInstalled[] = "Installation"
PluginsInstalled[] = "Monolog"
PluginsInstalled[] = "Intl"
PluginsInstalled[] = "CorePluginsAdmin"
PluginsInstalled[] = "CoreHome"
PluginsInstalled[] = "WebsiteMeasurable"
PluginsInstalled[] = "IntranetMeasurable"
PluginsInstalled[] = "CoreVisualizations"
PluginsInstalled[] = "Proxy"
PluginsInstalled[] = "API"
PluginsInstalled[] = "ExamplePlugin"
PluginsInstalled[] = "Widgetize"
PluginsInstalled[] = "Transitions"
PluginsInstalled[] = "LanguagesManager"
PluginsInstalled[] = "Actions"
PluginsInstalled[] = "Dashboard"
PluginsInstalled[] = "MultiSites"
PluginsInstalled[] = "Referrers"
PluginsInstalled[] = "UserLanguage"
PluginsInstalled[] = "DevicesDetection"
PluginsInstalled[] = "Goals"
PluginsInstalled[] = "Ecommerce"
PluginsInstalled[] = "SEO"
PluginsInstalled[] = "Events"
PluginsInstalled[] = "UserCountry"
PluginsInstalled[] = "GeoIp2"
PluginsInstalled[] = "VisitsSummary"
PluginsInstalled[] = "VisitFrequency"
PluginsInstalled[] = "VisitTime"
PluginsInstalled[] = "VisitorInterest"
PluginsInstalled[] = "ExampleAPI"
PluginsInstalled[] = "RssWidget"
PluginsInstalled[] = "Feedback"
PluginsInstalled[] = "CoreUpdater"
PluginsInstalled[] = "CoreConsole"
PluginsInstalled[] = "ScheduledReports"
PluginsInstalled[] = "UserCountryMap"
PluginsInstalled[] = "Live"
PluginsInstalled[] = "CustomVariables"
PluginsInstalled[] = "PrivacyManager"
PluginsInstalled[] = "ImageGraph"
PluginsInstalled[] = "Annotations"
PluginsInstalled[] = "MobileMessaging"
PluginsInstalled[] = "Overlay"
PluginsInstalled[] = "SegmentEditor"
PluginsInstalled[] = "Insights"
PluginsInstalled[] = "Morpheus"
PluginsInstalled[] = "Contents"
PluginsInstalled[] = "BulkTracking"
PluginsInstalled[] = "Resolution"
PluginsInstalled[] = "DevicePlugins"
PluginsInstalled[] = "Heartbeat"
PluginsInstalled[] = "Marketplace"
PluginsInstalled[] = "ProfessionalServices"
PluginsInstalled[] = "UserId"
PluginsInstalled[] = "CustomPiwikJs"
PluginsInstalled[] = "QueuedTracking"
PluginsInstalled[] = "TagManager"
PluginsInstalled[] = "DBStats"
PluginsInstalled[] = "TasksTimetable"
PluginsInstalled[] = "CustomDimensions"
PluginsInstalled[] = "CustomReports"
PluginsInstalled[] = "InvalidateReports"
PluginsInstalled[] = "EnvironmentVariables"

[QueuedTracking]
notify_queue_threshold_single_queue = 250000
; Below config is not really needed sincce the processQueue.sh script queries Redis manually before starting an process-job
backend = "redis"
redisHost = "%%REDIS_HOST%%"
redisPort = 6379
redisDatabase = 2
redisPassword = ""
queueEnabled = true
numQueueWorkers = %%QUEUEDTRACKING_WORKERS%%
processDuringTrackingRequest = false
numRequestsToProcess = %%QUEUEDTRACKING_NUM_REQUEST_TO_PROCESS%%
useSentinelBackend = false
sentinelMasterName = "HardCodedIn config.ini.php"

[Cache]
; available backends are 'file', 'array', 'null', 'redis', 'chained'
; 'array' will cache data only during one request
; 'null' will not cache anything at all
; 'file' will cache on the filesystem
; 'redis' will cache on a Redis server, use this if you are running Matomo with multiple servers. Further configuration in [RedisCache] is needed
; 'chained' will chain multiple cache backends. Further configuration in [ChainedCache] is needed
backend = %%MATOMO_CACHE_BACKEND%%

[ChainedCache]
backends[] = "array"
backends[] = redis

[RedisCache]
; Redis server configuration.
host = "%%REDIS_HOST%%"
port = 6379
; instead of host and port a unix socket path can be configured
;unix_socket = ""
timeout = 0.0
password = ""
database = 0
; In case you are using queued tracking: Make sure to configure a different database! Otherwise queued requests might
; be flushed

[Debug]
enable_sql_profiler = %%MATOMO_SQL_PROFILING%%

Some previous debugging effort was done in #1 but I was not able to find a definitive answer.