Run a PHP script from the command line with MAMP

我在 Mac 上開發 PHP 一直是用 MAMP 這個好用的 App。不過如果碰到需要在 Terminal 下以指令方式執行 PHP 程式就有點麻煩。

MAMP 裡的 php 路徑頗長…. 像這樣…

/Applications/MAMP/bin/php/php5.3.6/bin/php -v # 查詢 PHP 版本

所以還是來修改一下 ~/.bash_profile 吧。如果沒有這個檔案,自己建一個。

在裡面加入這一行…

export PATH=/Applications/MAMP/bin/php/php5.3.6/bin/:$PATH

存檔後離開。

在 Terminal 下輸入

source ~/.bash_profile

會重讀設定檔,然後剛才的修改就生效了。這樣以後要執行 PHP script 直接輸入 php 就可以了,方便許多。


Posted

in

by

Comments

One response to “Run a PHP script from the command line with MAMP”

  1. Very nice post. I just stumbled upon your blog and wanted to say that I’ve really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version