From 324e6abd468a3f479c370c98b75458d4e4a709d0 Mon Sep 17 00:00:00 2001 From: adphi Date: Thu, 26 Apr 2018 17:06:50 +0200 Subject: [PATCH] Added auto database and user creation --- 13.0/fpm/config/autoconfig.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/13.0/fpm/config/autoconfig.php b/13.0/fpm/config/autoconfig.php index b759f4d..c62da8e 100644 --- a/13.0/fpm/config/autoconfig.php +++ b/13.0/fpm/config/autoconfig.php @@ -1,11 +1,40 @@ connect_error) { + die("Connection failed: " . $connection->connect_error); + } + + // Create database + $create_database = "CREATE DATABASE " .$database; + $create_user = "GRANT ALL PRIVILEGES ON " .$database. ".* TO '" .$user."'@'%' IDENTIFIED BY '" .$password. "';"; + if ($connection->query($create_database) && $connection->query($create_user)) { + $AUTOCONFIG["dbtype"] = "mysql"; + $AUTOCONFIG["dbname"] = getenv('MYSQL_DATABASE'); + $AUTOCONFIG["dbuser"] = getenv('MYSQL_USER'); + $AUTOCONFIG["dbpass"] = getenv('MYSQL_PASSWORD'); + $AUTOCONFIG["dbhost"] = getenv('MYSQL_HOST'); + $autoconfig_enabled = true; + } else { + echo "Error creating database: " . $connection->error; + } + + $connection->close(); + } elseif (getenv('MYSQL_DATABASE') && getenv('MYSQL_USER') && getenv('MYSQL_PASSWORD') && getenv('MYSQL_HOST')) { $AUTOCONFIG["dbtype"] = "mysql"; $AUTOCONFIG["dbname"] = getenv('MYSQL_DATABASE');