2

I looked up all other questions regarding this, but they didn't help, so:

I'm running xampp(lite) on a Windows Server 2003 machine inside a domain, apache is installed as a service. The problem is: the PHP functions exec, system, passthru, etc. do nothing, no error messages (log level of apache is debug, php error_reporting is E_ALL), no program execution, nothing, it acts as if the function call wasn't there

I tried different approaches: exec, system, ..; proc_open and the WScript.Shell COM object, nothing worked. I tried using the absolute path, gave permissions to the user, tried tons of different .exe's doing different stuff, nothing worked, nothing every was executed.

I gave the Apache service my username; gave it its own apache user; gave it the system user and ticked "Allow interaction with desktop".

php safe_mode is off, also no functions are disabled.

When running apache NOT as as service, everything works perfectly.

Any idea what could be wrong?

TIA

2 Answers 2

6

If you try to launch GUI apps from a service in Vista, you'll have lots of trouble. As a security feature, Vista mediates the interaction of services with the desktop using 'Interactive Services Detection'.

That means, if you are running PHP as a module of an Apache service, you won't be able to launch GUI apps using any method. This kind of thing just won't work:

$WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run("notepad.exe", 7, false);

So, if you want to use Apache/PHP as a proxy for launching GUI apps, you'll need to run Apache as a console application.

First, if Apache is already installed as a service, you'll need to set it's startup type to "manual" using the services snap-in. (%SystemRoot%\system32\services.msc) Search for Services in the start menu search box.

Then add a shortcut to C:\apache\bin\httpd.exe (or wherever Apache is installed) to your Startup folder, and set that shortcut to start minimized. You can use an app like TrayIt! to force Apache down into the system tray.

Then use any of the methods outlined on the PHP website and you will be able to open a Windows application from PHP and see it's GUI.

Sign up to request clarification or add additional context in comments.

1 Comment

this is a very good solution which saved me many many hours, AND THE SAME CAN BE ACHIEVED without Trayit! by doing these steps: (1) (if your system needs to be Run as Admin, right-click httpd.exe / Properties / Compatibility / Run as Admin and OK; (2) run (if you haven't already) httpd.exe -k install -n "[apache service name of your choice]"; (3) In services.msc locate [apache service name of your choice] and in its properties / Log On card / select the option (•) This account: and fill in your credentials incl. pwd (for me it was .\[UserName]).
1

Check your PHP.ini file just incase those functions you've mentioned are in the disallowed setting. Not something standard from a XAMPP release though, but worth checking.

You say you're not getting any errors, I will assume your server is set as a service, therfore any commands sent using exe, system, passthru etc.. will be done in the background, so you won't see them running, but you should be able to capture data though.

<?php

//Start an object to capture data.
ob_start();

//Check we have access to the command line.
exec("ping google.com -n 1");

//Capture the output.
$output = ob_get_clean();

//Let's display it.
echo $output;

?>

Try the above and see what happens, you should get a response from command line, otherwise, it's possible it could be due to permissions.

2 Comments

as is wrote: functions are not disabled and permissions are okay. tried your example, it didn't work. I also tried different commands with will result in file creation or something else, so I see the result outside the php script ("echo 'foo' > bar.txt" or converting an jpeg with imagemagick) => no result
Okay, if you did a normal echo with some text, would you get output? Assuming yes, what OS are you running?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.