Jump to content

Cannot bootstrap index.php & run via PHP CLI?


hellomoto
 Share

Recommended Posts

When I include index.php and run the script via command line `php bootstrap.php` this error is returned:

PHP Warning:  Cannot modify header information - headers already sent by (output started at /pw/bootstrap/index.php:5) in /pw/index.php on line 41
404 page not found (no site configuration or install.php available)

I've tried moving the script around also and it's the same if external...

<?php namespace ProcessWire;

if (!class_exists('ProcessWire\Templates')) {
    // $pw_dir = dirname(dirname(__FILE__), 2); echo $pw_dir;
    $boot = "../pw/index.php";
    $boot = realpath($boot); echo $boot;
    require_once $boot;// $pw_dir.'/index.php';
    echo 'booted'; exit;
}

(so as to not include if ran from within PW instance, also tried with no condition)

Link to comment
Share on other sites

On 3/25/2024 at 4:22 PM, hellomoto said:
Cannot modify header information - headers already sent by (output started at /pw/bootstrap/index.php:5) in /pw/index.php on line 41

@hellomoto It's a common error. You are outputting data before the headers, but headers must be the first thing to output.

Headers are sent by ProcessWire, but you echo something before to include PW:

$boot = realpath($boot); echo $boot; // DO NOT echo something...
require_once $boot;// $pw_dir.'/index.php'; // ...BEFORE PW sent headers.

Also why do you use this code and not a simple include at start of file?

include __DIR__ . "/../index.php";
Link to comment
Share on other sites

Wow I missed that thank you. The conditional inclusion is so as to not repeat if running from within PW already, only require if ran from outside PW.

var_dump(class_exists('ProcessWire'));

returns false from within it so that's why it's \Templates...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...