bedrocklinux / bedrocklinux-userland

This tracks development for the things such as scripts and (defaults for) config files for Bedrock Linux
https://bedrocklinux.org
GNU General Public License v2.0
602 stars 65 forks source link

How to call `strat` and `brl` commands from PHP? #235

Closed sxiii closed 2 years ago

sxiii commented 2 years ago

Greetings.

I'm trying to use PHP shell_exec() function to run strat commands:

<?php
$output = `cat /etc/os-release`;
$output1 = `strat arch cat /etc/os-release`;
echo "<pre>hello debian: $output</pre><pre>hello arch: $output1</pre>";
?>

There is Caddy web server installed in Arch and PHP+PHP-FPM (FastCGI) Installed on debian. I'm getting the output from Debian OK, but no output from Arch:

hello debian: PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
... ... ... some more version info ... ... ...
hello arch: 

So, seems like all CHROOT-related commands, like "strat" and "brl" are unavailable under PHP shell_exec. Is there any way realistically I could allow these commands to be run, or, at least, the PHP interpreter to execute scripts/files/programs on both stratas?

Thanks a lot!

paradigm commented 2 years ago

I don't know PHP at all, but some general ideas that may help:

sxiii commented 2 years ago

Wow! I think you're right about PATH. Was too lazy to fiddle with that; so I made this really easy and fast fix based on your instructions:

$output1 = `/bedrock/bin/strat arch cat /etc/os-release`;

Now when I check the PHP file, I got:

hello debian: PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
... ...
hello arch: NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
... ...

This was actually just a test try, I will use both full paths; as well as running programs from other distros; just wanted to know what are my options.

Thank you so much @paradigm 👍🏻 Very quick and in-depth answer. 💯