Connecting to nvargus-daemon failed: No such file or directory

I have some basic python scripts up and working to access a pi camera v2 from my Nano. These scripts work fine from SSH or console but I cannot get the script to work properly when launched from PHP/Apache. The nano is running Apache and the script is executed as www-data user using exec() function. When it launches (using the same python binary as in testing) it throws this error:

(Argus) Error FileOperationFailed: Connecting to nvargus-daemon failed: No such file or directory (in src/rpc/socket/client/SocketClientDispatch.cpp, function openSocketConnection(), line 201)
(Argus) Error FileOperationFailed: Cannot create camera provider (in src/rpc/socket/client/SocketClientDispatch.cpp, function createCameraProvider(), line 102)
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:515 Failed to create CameraProvider

I have tried giving the www-data user every possible group for permissions which fixed earlier errors but it will not connect to the argus daemon to process the video stream. If I run the script from SSH/cli as the www-data user using “sudo -u www-data bash” it does work in that context. I am a bit rusty so not sure how php is spawning the process but it must be getting locked down in access to other sockets per the error?

Ideas?

So, did some more research and came up with some interesting stuff:

1.) Compiled a simple C++ opencv app to mimic the python stuff. Just opens the camera and sits there and it does the same thing when executed from PHP/apache
2.) Added a line to /usr/sbin/apachectl under the start section to start my simple test along with apache for fun. Guess what? It got the same error when systemd tried to start the app even outside of apache.

SO the issue seems the be the way systemd launches processes. I confirmed this by
1.) Stopping apache completely
2.) Starting apache from command line without systemd knowing
3.) Started my python script and all is well!!!

So what the heck? Does systemd spawn processes in a weird context or something? It was even launching the process as root but still flagging that error with systemd. It would be nice to have apache controlled normally but I can hack it out of systemd if necessary, just seems odd???

Ideas??

Could be Apache is starting and trying to use the camera before the nvargus daemon is ready. Similar things happen to me when I try to close the camera and re-open it again. Suggest tweaking the unit dependences and, if that fails, add a timeout to your app start and see if that fixes it.

In the first tests nothing is using the camera until I load a specific php page. The apache test was just to see what was causing the error apache lunching the process or systemd. Systemd must launch processes in some weird way, maybe missing something in the environment variables or putting it in some chroot jail? I should mention I am using scratch built opencv 4.1.0 from instructions on these forums. Maybe it works with stock l4t cv…