I want know how blogging systems works, what will happen when a user create a blog? I know every blogging system has a main site that user register on it , but how main site create sub-domain and source code for each user? how about database? is blog source code copied to every user folder? are all blogs use single core?
Your question is way too broad, but as an example of one possible approach, you could use the server name to choose an appropriate configuration for your app, and share source code.
<?php
$domain_map =
[
'foo.example.com' => 'foo',
'bar.example.com' => 'bar'
];
$domain = $_SERVER['SERVER_NAME'];
if(isset($domain_map[$domain])) {
$config = require __DIR__ . '/' . $domain_map[$domain] . '.config';
$app = new App($config);
// etc.
}