Add www-data to user's group, or the sudo group.
Have a dedicated PHP script running, listening to the named pipe and responding on the other one.
A PHP script is run that executes a system command, and it sends that input to the pipe.
The response from the dedicated PHP script is received, and returned to the client JavaScript with XMLHttpRequest.

Websockets won't need to be used.
System scripts can be run - possibly.
There might have to be more work put into the pipes, so that the script knows when to exit and stop waiting.  Perhaps a small delay will solve that.  If the script has not received a new line after half a second, after receiving an entire line, it could possibly wait for more input from another PHP script after sending a response to the client Javascript.