title: How to make it run the `exec()` command in PHP to edit some file in Mac OS X?
body: <p>When I have this PHP script.  </p>
  
  <pre><code>&lt;?php
      exec('/usr/local/bin/mate hello.txt');
  ?&gt;
  </code></pre>
  
  <p>It doesn't work on web browser with <a href="http://abc/hello.php" rel="nofollow noreferrer">http://abc/hello.php</a>, for example.</p>
  
  <p>The command of mate is 'TextMate app', and it's just for editing hello.txt.</p>
  
  <p>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 <code>exec()</code> function. </p>
  
  <ul>
  <li>Q : How can I make it run the PHP <code>exec()</code> function?</li>
  </ul>
  
  <p>I use Mac OS X 10.6.6/Apache/PHP5.</p>
  
  <h2>ADDED</h2>
  
  <p>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.</p>
  
  <h2>SOLVED</h2>
  
  <p>In terms of launching an Application in web browser (especially Safari) cannot be done with php, but with protocol handler. </p>
  
  <h3>Launching TextEditor to edit something.</h3>
  
  <p>TextEditor provides its own protocol handler <code>txmt://open/?url=file://THE_FILE_TO_EDIT"</code>. </p>
  
  <p>Or, you can have a button to  edit the file when clicked. </p>
  
  <pre><code>&lt;form action="txmt://open/?url=file://FILE_TO_EDIT" method="post"&gt;
    &lt;button type="submit"&gt;Edit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h3>Launching other app</h3>
  
  <p>You need to come up with your own protocol handler.  has all the necessary information with an example. </p>
  
  <p>For example, for launching PathFinder</p>
  
  Make URL types/schemes at Info.plist.
  
  <p>You may want to main window that pops up. You can set <code>Application is agent</code>. </p>
  
  <p><img src="https://i.stack.imgur.com/Jv8gI.png" alt="enter image description here"></p>
  
  Make the <code>pf:</code> protocol handler.
  
  <p>It just analyzes the input of <code>pf:INPUT_GINVEN</code>, to get the <code>INPUT_GIVEN</code> part to give it as a parameter to PathFInder. </p>
  
  <pre><code>@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;
  }
  </code></pre>
  
  <p>@end</p>
  
  Use the <code>pf:OPEN_DIRECTORY</code> protocol.
  
  <pre><code>&lt;form action="pf:DIRECORY_TO_OPEN" method="post"&gt;
      &lt;button type="submit"&gt;Open&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>