TheLiamRivers
Posts: 3
Joined: Wed May 25, 2016 9:49 pm

Make a PHP script start at raspberry boot

Wed May 25, 2016 9:53 pm

Hi everyone ! hope y'all OK ? as u can see in the title it's pretty clear, I just want to launch a php script just by booting the raspberry. Thanks

swampdog
Posts: 221
Joined: Fri Dec 04, 2015 11:22 am

Re: Make a PHP script start at raspberry boot

Wed Jun 08, 2016 8:56 am

/etc/rc.local is easiest but it'll run as root which you almost certainly don't want so put this above the "exit 0"..

Code: Select all

sudo -u {user} -i {/path/to/php/script}
eg: I have a user called "admin" and will invoke "z.php" as "admin"..

Code: Select all

sudo -u admin -i /wrk/z.php
..and "z.php" is..

Code: Select all

#!/usr/bin/php

<?php

ob_start();
phpinfo();
$x = ob_get_contents();
ob_end_clean();
file_put_contents("./wibble",$x."\n");
file_put_contents("/tmp/z",$x."\n");

?>
Btw, I don't know php so caveat emptor!

Return to “Other programming languages”