473,605 Members | 2,234 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 6601
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 ".Xauthorit y" 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******@techn icalbloke.comwr ote 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******@techn icalbloke.comwr ote 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'); ?>

...actuall y 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"
<webmasterNOSPA MTHA...@demogra cia.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....@techn icalbloke.comwr ote:
Richard wrote:
"r0g" <aioe....@techn icalbloke.comwr ote 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
2805
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 not necessary in "firstscript.php" to wait until it's finished. So how to launch
8
3867
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 boxs) .. data entry fields
6
2172
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 instance individually, but this does not appear possible using the Process object. When I run the example below the process object "p" can be viewed using Quick Watch however process object p2 is displayed as undefined, with the added affect of not...
1
2184
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 displayed on-screen as a .PDF stream. I need to have this page launch in it's own window leaving the first browser alone Here's the code I'm using to launch the report Private Sub btnPrintList_Click(ByVal sender As System.Object, ByVal e As...
10
2495
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 to go to an aspx page, click a button called "open notepad", then on ther server machine I would like to have the web app interact with a service installed on my server that handles the execution of different files. Does that makes sense?
13
2792
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
8441
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. if that's not possible then I at least need the code for useing some library for connecting to acrobat reader and giving the print command on windows and some thing similar on ubuntu linux. the problem is that I want to display reports in my...
2
2943
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: ******************************************************************************** deb http://in.archive.ubuntu.com/ubuntu/ dapper main restricted universe deb http://in.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse deb...
1
1648
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 application. The application name is dynamic and is selected from table. WScript.Echo verifies that it is calling the correct application and the path statement is correct. Also the application does reside where I am calling it from. The code...
0
8428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8290
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6749
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3913
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1546
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1274
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.