By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Can't launch graphical apps from php exec() on Ubuntu 8.04 system.

P: n/a
r0g
Hi There,

I'm trying to migrate a locally hosted page from windows to a private
Ubuntu development server and one of the key bits of functionality
(which used to work fine in Windows) was the ability for the page to
start a file browser via PHP's exec() function. I can't get this working
under Ubuntu though e.g.

<?php exec('nautilus /var/www'); ?>

Seemingly does nothing. This works fine at the command line. I have
tried other apps like open office to make sure it's not just nautilus
acting up and nada.

Interestingly though...

<?php print exec('nautilus /var/www'); ?>

....actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser! Also I tried calling
FFMpeg (the command line video transcoder) and that seems to run so
exec() is clearly asking these programs to run and there are no apache
errors in my logs.

All this leads me to suspect these apps aren't launching because the
user php is running as isn't allowed to launch graphical apps and thus
they are refusing but I'm pretty new to linux and I don't know if this
is a reasonable hunch, or indeed how to configure php to run with higher
/ other privileges if it were. Also, I'd like not to bork my new system
messing around with permissions when I'm not 100% sure what I'm doing so...

Has anyone here been able to launch graphical apps from exec() on a
linux based system? And if so - what's the trick!? :)

Many thanks,
Roger Heathcote.

http://movingtoubuntu.technicalbloke.co.uk
Sep 16 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
I V
On Tue, 16 Sep 2008 08:51:39 -0400, r0g wrote:
Interestingly though...

<?php print exec('nautilus /var/www'); ?>

...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!
Does it also print "cannot open display:" ?

[...]
All this leads me to suspect these apps aren't launching because the
user php is running as isn't allowed to launch graphical apps and thus
they are refusing but I'm pretty new to linux and I don't know if this
is a reasonable hunch, or indeed how to configure php to run with higher
/ other privileges if it were. Also, I'd like not to bork my new system
messing around with permissions when I'm not 100% sure what I'm doing
so...
How are you running the PHP program? If I run a PHP script from a
graphical terminal, I can start GUI programs with no difficulty.

There are at least two things that need to be the case to get a GUI
program running. The program needs to know what X server to connect to,
and it needs to have permissions to connect to that server. You specify
the X server with the DISPLAY environment variable; this will usually be
set automatically if you are running the PHP program from a terminal in
X, or from a GNOME panel or something similar; however, if you are
running the PHP script in some other manner, it likely won't know what X
server to connect to.

X has various ways of specifying permission to connect to a server, but
the most common one is using a file called ".Xauthority" in the users
home directory. Because only the user who is logged in at the X server
can read this file, they are the only user who can run GUI programs. So,
if you start the PHP user as the same user who is logged in at the X
server, you shouldn't have any problem with permissions. However, if the
PHP program is running as a different user, you will have to give that
user permission to access the X server.

Anyway, as the problem seems to be with connecting to the X server,
rather than with PHP itself, you might find that a better place to ask
this question is comp.windows.x .
Sep 16 '08 #2

P: n/a
*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
<?php print exec('nautilus /var/www'); ?>

...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!
You can't open server programs in remote clients via HTTP. Often, they
don't even run the same OS. All you can do is running programs *in the
server* and capture their text output.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
Sep 16 '08 #3

P: n/a
r0g
Álvaro G. Vicario wrote:
*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
><?php print exec('nautilus /var/www'); ?>

...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!

You can't open server programs in remote clients via HTTP. Often, they
don't even run the same OS. All you can do is running programs *in the
server* and capture their text output.
Hi escribió, thanks for the reply but I don't think I made it clear
enough. While I understand remote/public servers go to great lengths to
avoid people using/abusing apache to startup random programs the machine
in question here is a _local_ development machine. It is running Ubuntu
8.04 with the standard Gnome desktop, Apache/2.2.8 (Ubuntu)
PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch.

The application serves up locally generated pages and needs to run
commands to startup various local applications, such as file browsers
and FTP programs.

As I explained, I had this working fine in Windows using the exec()
command on a WAMP stack (Wamp5), so I think the problem is likely to be
permission based, having just switched to linux, but I'm not sure.

Anyone?

Thanks,
Sep 17 '08 #4

P: n/a

"r0g" <ai******@technicalbloke.comwrote in message
news:ga**********@aioe.org...
Álvaro G. Vicario wrote:
>*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
>><?php print exec('nautilus /var/www'); ?>

...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!

You can't open server programs in remote clients via HTTP. Often,
they
don't even run the same OS. All you can do is running programs *in
the
server* and capture their text output.

Hi escribió, thanks for the reply but I don't think I made it clear
enough. While I understand remote/public servers go to great lengths
to
avoid people using/abusing apache to startup random programs the
machine
in question here is a _local_ development machine. It is running
Ubuntu
8.04 with the standard Gnome desktop, Apache/2.2.8 (Ubuntu)
PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch.

The application serves up locally generated pages and needs to run
commands to startup various local applications, such as file
browsers
and FTP programs.

As I explained, I had this working fine in Windows using the exec()
command on a WAMP stack (Wamp5), so I think the problem is likely to
be
permission based, having just switched to linux, but I'm not sure.

Anyone?

Thanks,
Correct,
in Ubuntu the webserver runs as a different user account than the
logged in user.
If you would start it manually (as a user, not as a background
service) you can probably do the same as on windows.

You can change the user account the webserver runs under, this will
probably make your setup work immediately.
But be careful, this will also give all outside users the same
permission as this user!
If you keep it strictly local as you say, that should be no problem
though.
WAMP runs Apache and mySQL as a user program, not as a service.

The stand-alone Apache install runs (used to run??) as the system
account if used as a service.

(I still see it as a major flaw in the Apache installers that it is
installed as system account by default. )
That means that many things just work, where things will just not work
in antoher OS because of permissions.

Richard

Sep 17 '08 #5

P: n/a
r0g
Richard wrote:
"r0g" <ai******@technicalbloke.comwrote in message
news:ga**********@aioe.org...
>Álvaro G. Vicario wrote:
>>*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
<?php print exec('nautilus /var/www'); ?>

...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!
You can't open server programs in remote clients via HTTP. Often,
they
don't even run the same OS. All you can do is running programs *in
the
server* and capture their text output.
Hi escribió, thanks for the reply but I don't think I made it clear
enough. While I understand remote/public servers go to great lengths
to
avoid people using/abusing apache to startup random programs the
machine
in question here is a _local_ development machine. It is running
Ubuntu
8.04 with the standard Gnome desktop, Apache/2.2.8 (Ubuntu)
PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch.

The application serves up locally generated pages and needs to run
commands to startup various local applications, such as file
browsers
and FTP programs.

As I explained, I had this working fine in Windows using the exec()
command on a WAMP stack (Wamp5), so I think the problem is likely to
be
permission based, having just switched to linux, but I'm not sure.

Anyone?

Thanks,

Correct,
in Ubuntu the webserver runs as a different user account than the
logged in user.
If you would start it manually (as a user, not as a background
service) you can probably do the same as on windows.

You can change the user account the webserver runs under, this will
probably make your setup work immediately.
But be careful, this will also give all outside users the same
permission as this user!
If you keep it strictly local as you say, that should be no problem
though.
WAMP runs Apache and mySQL as a user program, not as a service.

The stand-alone Apache install runs (used to run??) as the system
account if used as a service.

(I still see it as a major flaw in the Apache installers that it is
installed as system account by default. )
That means that many things just work, where things will just not work
in antoher OS because of permissions.

Richard
Thanks for your reply Richard,

I've just been looking into changing the webserver account permissions
and, given my newness to linux, it looks like a bit of a nightmare.
Indeed doing this even on a local/private machine makes my skin crawl a
bit! So...

I'm going to try a different tack and write a small daemon in python
that runs as me and launches programs from a predefined set in response
to a datagram poke via a local socket. This should be safer, less hassle
and more fun to write than those :-)

Thanks again,

Roger Heathcote.
Sep 17 '08 #6

P: n/a
On 16 Sep, 20:38, "Álvaro G. Vicario"
<webmasterNOSPAMTHA...@demogracia.comwrote:
*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
<?php print exec('nautilus /var/www'); ?>
...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!

You can't open server programs in remote clients via HTTP. Often, they
don't even run the same OS. All you can do is running programs *in the
server* and capture their text output.
This is a very confused answer.

OP is talking about Ubuntu, therefore most likely about X Window
applications. In X Window terminology, the user sits at the server
(where the application is displayed) but the application runs on the
client.

There is nothing to stop the user starting up a program on the same
box where PHP is sitting - this is the HTTP server, but the X client.

C.
Sep 17 '08 #7

P: n/a
On 17 Sep, 11:18, r0g <aioe....@technicalbloke.comwrote:
Richard wrote:
"r0g" <aioe....@technicalbloke.comwrote in message
news:ga**********@aioe.org...
Álvaro G. Vicario wrote:
*** r0g escribió/wrote (Tue, 16 Sep 2008 08:51:39 -0400):
<?php print exec('nautilus /var/www'); ?>
>>...actually prints: "Run 'nautilus --help' to see a full list of
available command line options." in my browser!
You can't open server programs in remote clients via HTTP. Often,
they
don't even run the same OS. All you can do is running programs *in
the
server* and capture their text output.
Hi escribió, thanks for the reply but I don't think I made it clear
enough. While I understand remote/public servers go to great lengths
to
avoid people using/abusing apache to startup random programs the
machine
in question here is a _local_ development machine. It is running
Ubuntu
8.04 with the standard Gnome desktop, Apache/2.2.8 (Ubuntu)
PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch.
The application serves up locally generated pages and needs to run
commands to startup various local applications, such as file
browsers
and FTP programs.
As I explained, I had this working fine in Windows using the exec()
command on a WAMP stack (Wamp5), so I think the problem is likely to
be
permission based, having just switched to linux, but I'm not sure.
Anyone?
Thanks,
Correct,
in Ubuntu the webserver runs as a different user account than the
logged in user.
If you would start it manually (as a user, not as a background
service) you can probably do the same as on windows.
You can change the user account the webserver runs under, this will
probably make your setup work immediately.
But be careful, this will also give all outside users the same
permission as this user!
If you keep it strictly local as you say, that should be no problem
though.
WAMP runs Apache and mySQL as a user program, not as a service.
The stand-alone Apache install runs (used to run??) as the system
account if used as a service.
(I still see it as a major flaw in the Apache installers that it is
installed as system account by default. )
That means that many things just work, where things will just not work
in antoher OS because of permissions.
Richard

Thanks for your reply Richard,

I've just been looking into changing the webserver account permissions
and, given my newness to linux, it looks like a bit of a nightmare.
Indeed doing this even on a local/private machine makes my skin crawl a
bit! So...

I'm going to try a different tack and write a small daemon in python
that runs as me and launches programs from a predefined set in response
to a datagram poke via a local socket. This should be safer, less hassle
and more fun to write than those :-)

Thanks again,

Roger Heathcote.
Something wrong with writing a daemon in PHP?

C.
Sep 17 '08 #8

P: n/a
r0g
>>
>I've just been looking into changing the webserver account permissions
and, given my newness to linux, it looks like a bit of a nightmare.
Indeed doing this even on a local/private machine makes my skin crawl a
bit! So...

I'm going to try a different tack and write a small daemon in python
that runs as me and launches programs from a predefined set in response
to a datagram poke via a local socket. This should be safer, less hassle
and more fun to write than those :-)

Thanks again,

Roger Heathcote.

Something wrong with writing a daemon in PHP?

C.
Now I know it may be controversial to say it here but say it I must...

It's faster to write almost anything in python than PHP! ;-P

No disrespect to PHP though, this applies to pretty much every other
language. They all have their pros and cons, the big pro of python being
the rapid development (and no god damned semicolons to forget!)... if
execution speed or memory usage were a consideration here I'd use
something else, like PHP :-)

Roger.
Sep 17 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.