Giving access to localhost PHP to execute external programs (like Brackets) - Mac OSX -


i'm trying find ways allow local automation on mac (os x yosemite) through use of running php on localhost (so can throw simple gui whatever i'm automating).

the problem getting shell commands work with appropriate access... here's started:

  1. make duplicate of "/etc/php.ini.default" , rename "/etc/php.ini"
  2. add "safe_mode = off" php.ini file
  3. restart localhost - "sudo apachectl restart"

after that, can test code work , print results in php page:

$result = shell_exec('ls'); echo $result; 

now want able open files editor program (brackets). can in terminal using command:

brackets /users/myusername/mypath/myfile.html 

that... works in terminal in php script, doesn't work:

$result = shell_exec('brackets /users/myusername/mypath/myfile.html'); echo $result; 

i'm assuming user or permission issue? don't sort of output or error. know locahost runs "_www" user , group. tried changing in /etc/apache2/httpd.chmod changing "_www" "myusername", php files no longer work in safari after that.

anyways, feel i'm close, don't know try next! appreciate answers :) (also i'm aware bit of security downgrade, don't mind since strictly local , not public).

this do. go command line , type sudo visudo. open vim (look how use vim if don't know how) can edit sudoers file, controls can use sudo permissions what. have done on ubuntu machine give php access etherwake. sudoers file it:

user_alias      php_user = www-data cmnd_alias      etherwake = /usr/sbin/etherwake php_user        = nopasswd: etherwake 

just switch www-data name of php user on computer.

i believe can specify rather cmnd_alias etherwake give access commands warned: extremely dangerous thing do. safer give access specific commands, otherwise authenticate user on computer anything.

any command php needs run administrator should start sudo. ex:

$result = shell_exec('sudo ls'); 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -