I created a tmux session on a Ubuntu Server 18.04. In order to give multiple linux users access to the same session I followed these instructions. Everything works fine when I'm trying to access the tmux socket/session from "regular" users over the command line.
I'm about to script a website on which I want to start or kill this session. Like in the tutorial provided above, I added the www-data user to the group which shares the tmux socket. In order to execute this tmux commands over php as superuser I added this line www-data ALL=NOPASSWD: /usr/bin/tmux
to the visudo file.
When I want to kill the already running session with php(shell_exec) it says:
"no server running on watten_tmux_socket".
Although I am able to kill this session with the same command as a "regular" user. Whats wrong here?
sudo tmux -S /tmp/watten_tmux_socket kill-session -t WattenServer
EDIT: Starting a session on a socket over php doesn't work either. No session and no socket gets created under /tmp, while in the command line it works.
Ok, i did a workaround. Using sudo in PHP is very insecure so now when i want to start or kill a new tmux session over php i modify the content of a txt file (something like serverstate:on). I installed incron apt-get install incron
. With the help of the incrontab you can register some sort events whenever a file changes. So now whenever i modify the content of this file, a script gets executed wich starts or kills the tmux session.
Reference: Incron tutorial