How to run a PHP script from the command line with MAMP?

前端 未结 4 1698
一整个雨季
一整个雨季 2020-12-12 19:26

I have MAMP installed. Now I am trying to run a script from the command line, but I can\'t seem to get it to work.

How should I set up my environment so that I can r

相关标签:
4条回答
  • 2020-12-12 19:49

    Please note that with version 2.0.5 of MAMP, the path has changed. It is now one of the following:

    /Applications/MAMP/bin/php/php5.2.17/bin/
    /Applications/MAMP/bin/php/php5.3.6/bin/
    

    Therefore the command to add MAMP's php command should probably look like this:

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

    or like this (depending on which version of PHP you want to use):

    export PATH=/Applications/MAMP/bin/php/php5.3.6/bin/:$PATH
    
    0 讨论(0)
  • 2020-12-12 19:56

    Run this in your Terminal:

    export PATH=/Applications/MAMP/bin/php5/bin/:$PATH
    

    Should do the trick. It will - as Tom Haigh mentioned - add the MAMP PHP executable to the path so you can use "php" instead of the full path.

    0 讨论(0)
  • 2020-12-12 20:02

    Yes, I think it is here: /Applications/MAMP/bin/php5/bin/php

    You can either add /Applications/MAMP/bin/php5/bin/ to the front of your path or create a symlink in /usr/bin (there probably is one there already for the default PHP installation)

    0 讨论(0)
  • 2020-12-12 20:04

    Another way that works that may be a little cleaner with regard to PHP versions is to create an alias in your bash profile that points to the specific php binary that you want to run when you run things like composer or other cli tools. This has the benefit of avoiding some potential library and php.ini config compatibility issues with the installed version of php in OSX.

    For instance, if you want to point to php 5.4.1 in MAMP, edit your .bash_profile file in your editor of choice (nano, vi, etc.):

    # nano ~/.bash_profile
    

    Add this below your PATH statement:

    alias php=/Applications/MAMP/bin/php/php5.4.10/bin/php
    

    Save and quit (CTRL+X in nano, :wq in vi). Quit Terminal. The next time you try to call php from the cli, you'll be using the 5.4.10 version installed with MAMP.

    Remember to update this path if you update MAMP with a more recent version of PHP.

    0 讨论(0)
提交回复
热议问题