php / config.inc.php
edwagbb's picture
Update config.inc.php
6f3e083
raw
history blame
1.25 kB
<?php
// site root path
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__));
// plugin directory (relative path)
define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins');
// theme directory (relative path)
define('__TYPECHO_THEME_DIR__', '/usr/themes');
// admin directory (relative path)
define('__TYPECHO_ADMIN_DIR__', '/admin/');
// register autoload
require_once __TYPECHO_ROOT_DIR__ . '/var/Typecho/Common.php';
// init
\Typecho\Common::init();
//DB_COON_STR = 'mysql://user:[email protected]:3306/dbname'
if(!getenv('DB_HOST')){
$matches = [];
preg_match("/^(mysql:\/\/)?([^:]*?):(.*?)@([^@^:]*?):?(\d+)?\/([^\/]*?)$/", getenv('DB_COON_STR'), $matches);
putenv('DB_USER='.$matches[2]);
putenv('DB_PASS='.$matches[3]);
putenv('DB_HOST='.$matches[4]);
putenv('DB_PORT='.($matches[5] ? $matches[5] : '3306'));
putenv('DB_NAME='.$matches[6]);
}
// config db
$db = new \Typecho\Db('Pdo_Mysql', 'typecho_');
$db->addServer(array (
'host' => getenv('DB_HOST'),
'port' => intval(getenv('DB_PORT')),
'user' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8mb4',
'database' => getenv('DB_NAME'),
'engine' => 'InnoDB',
'sslCa' => '',
'sslVerify' => true,
), \Typecho\Db::READ | \Typecho\Db::WRITE);
\Typecho\Db::set($db);