473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
8 6593
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
*** 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
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

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2798
by: Bob Bedford | last post by:
I've a script that must "launch" an other script on some situations. firstscript.php: .... If ($newarticle) //launch secondscript.php .... The "secondscript.php" may take quite long, and is...
8
3857
by: tmb | last post by:
1 - Can you build an entire web page or site with Java... sorta like you can with Flash? 2 - Can you do... .. Drag & Drop .. Push Buttons .. Hot Spot .. Hot Object .. Pull Down's (combo...
6
2164
by: gizmo | last post by:
I have a requirement to initiate more than one instance of an application using the filenames. (the example below will start two instances of MS Word). My problem is that I need to kill each...
1
2180
by: Jacob | last post by:
I have several web apps that I want to redirect to a new page, but have that page open in a new browser window. The basic scenario is that I have a CrystalReport object that gets created and...
10
2484
by: Steve | last post by:
I want to make a web application that will run on my home server and would like to be able to have the web application interact with another, winforms application. For example, let's say I wanted...
13
2771
by: Sree | last post by:
If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv) { int i; for(i=0;i<argc;i++) printf("%s",argv); }
17
8430
by: krishnakant Mane | last post by:
hello all, I am stuck with a strange requirement. I need a library that can help me display a pdf file as a report and also want a way to print the same pdf file in a platform independent way....
2
2936
by: Pradnyesh Sawant | last post by:
Hello, I have a newly installed ubuntu 6.06 system. I am trying to install pyqt4 on it, but without success. The contents of the /etc/apt/sources.list file are:...
1
1637
BezerkRogue
by: BezerkRogue | last post by:
I have created a VB Script to synchronize software versions and then launch an application on the system it is run against. The script runs and generates no errors but will not launch the second...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.