File size: 1,251 Bytes
2c5def5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb62e17
d20961a
 
30a992d
d20961a
 
 
 
 
 
6f3e083
2c5def5
d20961a
2c5def5
d20961a
 
 
 
 
 
 
 
c402e44
2c5def5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?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:pass@x.x.x.x: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);