Home » Php » bash – PHP Interactive – Load File From Command Line

bash – PHP Interactive – Load File From Command Line

Posted by: admin July 12, 2020 Leave a comment

Questions:

Is there a way, from a bash script and/or a terminal, to run php interactively and load in a predefined file at the same time?

Essentially, I want to do the following two steps in a single step:

shell# php -a
Interactive mode enabled

php > require_once('ABSOLUTE_PATH_TO_FILE');

I tried using php -a --file='ABSOLUTE_PATH_TO_FILE' but the functions I want to load do not become available in interactive mode.

How to&Answers:

If you have a test.php file with this contents

<?php
function asd() {
    echo "Hi!";
}
?>

You must use:

php -a -d auto_prepend_file=test.php