Home  >  Article  >  Backend Development  >  Using MAMP's PHP to replace the system's own PHP under OSX

Using MAMP's PHP to replace the system's own PHP under OSX

WBOY
WBOYOriginal
2016-07-28 08:27:50921browse

The PHP replacement system using MAMP under OSX comes with PHP

Foreword

As we all know, OSX comes with itPHPApache, obviously these are not what we need.
Many people will install an integrated environment as their development environment. For example, I chose MAMP and the PHP version is 7.0.

Problem

I executed php -v in the OSX terminal, and what appeared was the built-in PHP5.5php -v,出现的是自带的PHP5.5

<code>yu@bogon ~ $ php -v 
PHP <span>5.5</span>.<span>31</span> (cli) (built: Feb <span>20</span><span>2016</span><span>20</span>:<span>33</span>:<span>10</span>) 
Copyright (c) <span>1997</span>-<span>2015</span> The PHP Group
Zend Engine v2.<span>5.0</span>, Copyright (c) <span>1998</span>-<span>2015</span> Zend Technologies</code>

这样就会出现在运行一些框架的命令行工具,比如Yii、Laravel,会出现问题。

解决方案

删除自带php和apache

OSX之所以会自带apache和php环境,是因为一些系统工具会使用,如果删掉的话,可能导致某些工具不能使用。

不推荐这个方法。

添加到环境变量

查看所用的bash

<code><span>echo</span><span>$SHELL</span></code>
  • csh或者tcsh,C Shell
  • bash,sh,zsh,Bourne Shell

修改配置文件

我们可以修改的配置文件有下面几种

  • /etc/profile ,全局环境变量,不要修改
  • /etc/bashrc,系统级环境变量,可以修改
  • ~/.bash_profile ,用户级环境变量,可以修改

经过测试,居然都没有生效。。。。

所以采用最后的方式。

alias 别名

由于我采用的是zsh,所修改的配置文件的位置是~/.zshrc

<code>alias php=<span>"/Applications/mamp/php/bin/php"</span></code>
like this Problems will occur when running command line tools of some frameworks, such as Yii and Laravel.

Solution

Delete the built-in php and apache
  • The reason why OSX comes with its own apache and php environment is because some system tools will use it. If deleted, some tools may not be usable.
  • This method is not recommended.
Add to environment variables

Check the bash used

<code>yu@bogon ~ $ php -v
PHP <span>7.0</span>.<span>0</span> (cli) (built: Dec  <span>4</span><span>2015</span><span>01</span>:<span>16</span>:<span>36</span>) ( NTS )
Copyright (c) <span>1997</span>-<span>2015</span> The PHP Group
Zend Engine v3.<span>0.0</span>, Copyright (c) <span>1998</span>-<span>2015</span> Zend Technologies
    with Zend OPcache v7.<span>0.6</span>-dev, Copyright (c) <span>1999</span>-<span>2015</span>, by Zend Technologies</code>

csh or tcsh, C Shell

    bash, sh, zsh, Bourne Shell
  • Modify the configuration file

  • The configuration files we can modify include the following
  • /etc/profile, global environment variables, do not modify
  • /etc/bashrc, system-level environment variables, you can modify
~/.bash_profile, user-level environment variables, It can be modified

After testing, it didn’t take effect. . . .

So adopt the last method.

🎜alias alias🎜🎜Since I am using zsh, the location of the modified configuration file is ~/.zshrc🎜🎜Add alias at the end of the configuration file to let the php command point directly to MAMP's php The reason why the path 🎜rrreee🎜 is adopted in this way is that it is safe and does not affect the convenience of calling system PHP by other software. Current users will directly call PHP7. If I delete MAMP, I can modify the alias directly to avoid changes. What an unexpected bug🎜🎜🎜Result🎜rrreee🎜References🎜🎜🎜http://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp- path🎜🎜http://blog.sina.com.cn/s/blog_68431a3b0102vpny.html🎜🎜https://www.zhihu.com/question/20916296🎜🎜http://elf8848.iteye.com/blog/1582137 🎜🎜🎜').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i 🎜').text(i)); }; $numbering.fadeIn(1700); }); }); 🎜 🎜 The above introduces the use of MAMP under OSX to replace the system's own PHP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials. 🎜 🎜 🎜
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn