When I have this PHP script.
<?php
exec('/usr/local/bin/mate hello.txt');
?>
It doesn’t work on web browser with http://abc/hello.php, for example.
The command of mate is ‘TextMate app’, and it’s just for editing hello.txt.
Is this some php permission problem?
I just need to run some commands on my local web server (I’m the only user), so I can open the permission to run this seemingly dangerous exec() function.
- Q : How can I make it run the PHP
exec()function?
I use Mac OS X 10.6.6/Apache/PHP5.
ADDED
I guess it’s not possible to launch something with PHP on my Mac, but for my purposes to open an TextMate editor to edit something, using txmt protocol works perfectly fine.
SOLVED
In terms of launching an Application in web browser (especially Safari) cannot be done with php, but with protocol handler.
Launching TextEditor to edit something.
TextEditor provides its own protocol handler txmt://open/?url=file://THE_FILE_TO_EDIT".
Or, you can have a button to edit the file when clicked.
<form action="txmt://open/?url=file://FILE_TO_EDIT" method="post">
<button type="submit">Edit</button>
</form>
Launching other app
You need to come up with your own protocol handler. has all the necessary information with an example.
For example, for launching PathFinder
Make URL types/schemes at Info.plist.
You may want to main window that pops up. You can set Application is agent.

Make the pf: protocol handler.
It just analyzes the input of pf:INPUT_GINVEN, to get the INPUT_GIVEN part to give it as a parameter to PathFInder.
@implementation URLHandlerCommand!
- (id)performDefaultImplementation {
NSString *urlString = [self directParameter];
NSLog(@"url :=: %@", urlString);
NSArray *components = [urlString componentsSeparatedByString: @":"];
NSString* string2 = (NSString*) [components objectAtIndex:1];
NSLog(@"url :=: %@", string2);
[[NSWorkspace sharedWorkspace] openFile:string2 withApplication:@"Path Finder"];
[[NSApplication sharedApplication] terminate:nil];
return nil;
}
@end
Use the pf:OPEN_DIRECTORY protocol.
<form action="pf:DIRECORY_TO_OPEN" method="post">
<button type="submit">Open</button>
</form>
If the script is running on a remote web server, then the
exec()will run on the remote server, not the local machine. My guess is you want the command run on the local computer that is visiting the website, but this is not possible for very good (security) reasons.What you probably want to use is the
txmt://protocol as described in the Textmate Manual: