Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I actually try to launch a gnome-terminal with a PHP script, and seems I have some problems with the users www-data;

My script only makes an ls -l command in a directory (is just for a test) and I run it with a php page on my local website.

Here is the gnome-terminal command in my bash script (it runs perfectly when I double-click):

gnome-terminal --working-directory=/opt/cuckoo -x bash -c "ls -l"

and here is the call on the php-page:


I have some "echo" in my script and I see it in the PHP page after I try to run the script with the website.

I think www-data doesn't have the permissions so I try to give the user ownership of the script with the chown command with no result, and at last I tried the sudo visudo command and gave www-data root permissions for this script only (with NO PASSWD arg).

It didn't work. I tried to change the php command, replacing system by exec, and show the result with $output but it's the same as well.

Can PHP really run a terminal or did I maybe fool myself?

share|improve this question
i already ask my question with php tag — where? – slhck May 23 '12 at 8:42
What exactly are you trying to do? I don't think you need gnome-terminal at all. – Keith May 23 '12 at 8:43
Won't gnome-terminal need an xserver? – Paul May 23 '12 at 9:35
Why not just use exec for all of the commands you want to run? It seems like overkill to spawn a terminal just to run commands when you can run them directly from PHP. – Breakthrough May 23 '12 at 11:54
slhck :… Keith: yes it's my fault but ls is just for a example, i want to run a python script who need 2 gnome terminal open, my script do that very well so i just want to run it with php interface. Paul: i can run the script well, you think i need xserver if i want to run it with php ? Breakthrough : i try with exec too and shell_exec, but it doesn't made any results. i think is the problems come from the permissions – zoomb May 23 '12 at 13:32

Something that you have to take into account

  1. If you want to ls a directory, "who" run that command could traverse that folder (so, +x permission is absolutely necessary)
  2. Is your php script running under a server? If it does, maybe you have to change the owner in agreement with this
  3. Dependent on the second point: please keep attention when you chown on files
share|improve this answer
The php script is on the folder var/www/. It,s a local server, but i already add my local user to the www-data group and try after with visudo to give full permissions to the user www-data for the script, and give the ownership too with chown, maybe i have forget something ? – zoomb May 23 '12 at 14:05
@zoomb Under what user runs your page? – DonCallisto May 23 '12 at 14:24
under the www-data user, int the /var/www/mysite/path i give him full permissions for the script and add the local user in the www-data group – zoomb May 23 '12 at 14:29
I suppose that he would run in "normal" condition. Maybe gnome-terminal are just different respect other kind of terminal – DonCallisto May 23 '12 at 14:32
yes i think too, i try with another command than gnome-term so – zoomb May 23 '12 at 14:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.