Running Multiple Websites from One Typecho Installation

Machine-translated (anthropic, claude-haiku-5-5) from the Chinese original. Read the original in 中文

Contents

Preface

Sometimes, when building theme demo sites, you have to set up each one separately as a new program, which is quite troublesome. Today I'll share a new method that lets you install just one program and build multiple websites!

Analysis

First, bind two domain names (hereinafter called Domain A and Domain B) to the same directory on the hosting space.

Next, upload Typecho to the hosting space. When you open Domain A, Typecho will automatically detect and start the installation. During installation, please change the database table prefix to A_. The installation process goes very smoothly.

After the installation is complete, download the file automatically generated by the program config.inc.php as a backup, and delete config.inc.php on the server.

Open the site with Domain B. At this point, Typecho will again automatically detect and start the installation. This time, please change the database table prefix to B_. The installation process is equally smooth.

Download the config.inc.php file again, and compare the two files. We can see that the only difference between them lies in the database and table prefix at the end.

Procedure

These two files are very similar, so we can imitate WordPress and let it also build multiple sites from one program.

Code

text
if($_SERVER["HTTP_HOST"]=="A域名.com" || $_SERVER["HTTP_HOST"]=="www.A域名.com"){
$db = new Typecho_Db('Mysql', 'A_');
}
else if($_SERVER["HTTP_HOST"]=="B域名.com" || $_SERVER["HTTP_HOST"]=="www.B域名.com"){
$db = new Typecho_Db('Mysql', 'B_');
}
$db->addServer(array (
'host' => 'localhost',
'user' => '数据库用户名',
'password' => '数据库密码',
'charset' => 'utf8',
'port' => '3306',
'database' => '数据库名',
), Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set($db);

Comments