19
2020
01

mac下php环境搭建

brew install php72,安装后可通过php-v 查看版本。

设置为默认的版本

修改 vim ~/.bash_profile

exportPATH=/Applications/MAMP/bin/php/php7.2.7/bin:$PATH

#/Applications/MAMP/bin/php/php7.2.7/bin是默认的php版本路径,请按照当前环境自行更改

保存重载环境变量

source~/.bash_profile

修改后可使用which php查看默认版本


安装成功后提示:

To enable PHP in Apache add the following to httpd.conf and restart Apache:

    LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so


    <FilesMatch \.php$>

        SetHandler application/x-httpd-php

    </FilesMatch>


Finally, check DirectoryIndex includes index.php

    DirectoryIndex index.php index.html


The php.ini and php-fpm.ini file can be found in:

    /usr/local/etc/php/7.2/


php@7.2 is keg-only, which means it was not symlinked into /usr/local,

because this is an alternate version of another formula.


If you need to have php@7.2 first in your PATH run:

  echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile

  echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile


For compilers to find php@7.2 you may need to set:

  export LDFLAGS="-L/usr/local/opt/php@7.2/lib"

  export CPPFLAGS="-I/usr/local/opt/php@7.2/include"



To have launchd start php@7.2 now and restart at login:

  brew services start php@7.2

Or, if you don't want/need a background service you can just run:

  php-fpm



切换php版本

在apache配置文件中下面添加以下内容 libphp 模块:

#LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so

#LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so

#LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so

#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so

需要使用某个版本则删除对应的#,去掉注释即可。

然后重启apche和php

重启apche      sudo /usr/sbin/apachectl restart


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。