0

Hey guys is there a way to run php file in chrome or in any other browser using terminal.If I run my php file it automatically runs on my default browser but I just want to run on different browser using terminal(Mac OS).

TryingToLearn
  • 365
  • 2
  • 4
  • 15

1 Answers1

0

Use the "open" command and specify a different browser with the "-a application" flag.

open -a /path/to/Chrome/binary yourfile.php

Manpage for "open" is here.

Of course, you can also make an alias for that to save typing:

alias chrome="open -a /path/to/Chrome/binary yourfile.php"

then you can just type

chrome

If you have spaces in the path to your Chrome binary, you will need to escape them when defining the alias, something like this:

alias chrome="open -a \"/Applications/Google Chrome.app/contents/MacOS/Google Chrome\" yourfile.php"
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I am trying to achieve hostc filename using `alias hostc="open -a /Applications/Google\ Chrome.app/ http://localhost:8888/Sandbox/$1"` but it says file not found.how can I solve this problem. – TryingToLearn Dec 07 '13 at 15:27
  • Oh, I see. The problem is that your "path to app" is incomplete, you need to add "/Contents/MacOS/Google Chrome" onto the end. The actual binary is buried deeper inside the Chrome.app. I have amended again. – Mark Setchell Dec 07 '13 at 15:48
  • I think you need a filename at the end, not an "http:" path. – Mark Setchell Dec 07 '13 at 15:57
  • If u don't give that $1 then it opens the list of files under Sandbox directory and I can run any php or html file by clicking it.For php we need local server to be running so am http alongside and the parameter to that link so that I can open each file at a time. – TryingToLearn Dec 07 '13 at 16:04
  • Also you are trying to add a parameter to the alias with $1 which isn't directly possible, see http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter – Mark Setchell Dec 07 '13 at 16:11
  • Actually am using zsh I will have a look . – TryingToLearn Dec 07 '13 at 16:20