What is the common practice for setting up subdomains in PHP applications?

When setting up subdomains in PHP applications, a common practice is to use a wildcard subdomain in the DNS settings to route all subdomains to the main application. Then, within the PHP application, you can parse the subdomain from the URL and use it to determine the appropriate content or functionality to display.

$subdomain = explode('.', $_SERVER['HTTP_HOST'])[0];

switch ($subdomain) {
    case 'sub1':
        // Handle subdomain specific logic for sub1
        break;
    case 'sub2':
        // Handle subdomain specific logic for sub2
        break;
    default:
        // Handle default logic for main domain
        break;
}