Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mindhunter's avatar

How to Exec PHP script from laravel?

Hi everybody. I tried to create some PHP script files in laravel public folder like this:

$filename = $orderID.'-'.time().'.php';
$newfile = fopen($filename, 'w');
$str = '...test...';
fwrite($newfile, $str);
fclose($newfile);
return $filename;

It creates the file successfully in Public folder. My first Question is how can i change the path for my script when creating it? My second problem is How to call it? when i called it from Laravel controller with:

exec('php '.$order->filename.' > /dev/null 2>&1 &');

it raise the "The system cannot find the path specified." error in terminal. Any help would be appreciated.

0 likes
2 replies
ahmadmayahi's avatar
exec('php '.public_path($order->filename).' > /dev/null 2>&1 &');
Snapey's avatar

why?

Why use laravel (php) framework to launch standalone php scripts?

You are almost certainly trying to solve the wrong problem.

Please or to participate in this conversation.