phpphp-builtin-server

Can I load .phtml files using PHP builtin server?


With the default config, PHP's built-in server treats .phtml files as static resources. Is there any way to make it process them as regular .php scripts?


Solution

  • With a router script you should be able to check for phtml and then just include the file.

    <?php
    if (preg_match('/\.(?:php|phtml)$/', $_SERVER["REQUEST_URI"])) {
        require('./' . $_SERVER["REQUEST_URI"]);
        return;
    }
    return false;
    

    http://php.net/manual/en/features.commandline.webserver.php#example-405