简体   繁体   English

在AMPPS(OSX)中为PHP设置“ $ PATH”变量

[英]setting “$PATH” variables for PHP in AMPPS (OSX)

I have a question about setting "$PATH" variables for PHP scripts in AMPPS (On OSX 10.10 Yosemite). 我有一个关于在AMPPS中设置PHP脚本的“ $ PATH”变量的问题(在OSX 10.10 Yosemite上)。

The PHP in AMPPS seems to run as my user "danny", however the $PATH it sees is different. AMPPS中的PHP似乎以我的用户“ danny”的身份运行,但是它看到的$ PATH是不同的。 Here's what I see from my terminal: Dannys-MacBook-Air:AMPPS danny$ echo $PATH; 这是我从终端上看到的内容:Dannys-MacBook-Air:AMPPS danny $ echo $ PATH; /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 在/ usr / local / bin目录:在/ usr / bin中:/ bin中:/ usr / sbin目录:/ sbin目录

And here is what I get within a PHP script by printing out $_ENV: ["PATH"]=> string(29) "/usr/bin:/bin:/usr/sbin:/sbin" ["USER"]=> string(5) "danny" 这是我通过打印$ _ENV在PHP脚本中得到的内容:[“ PATH”] => string(29)“ / usr / bin:/ bin:/ usr / sbin:/ sbin” [“ USER”] = >字符串(5)“丹尼”

I tried doing "putenv()", tried doing "shell_exec" with a different $PATH, I tried doing SetEnv in .htaccess and in the Apache config file. 我尝试执行“ putenv()”,尝试使用不同的$ PATH执行“ shell_exec”,我尝试在.htaccess和Apache配置文件中执行SetEnv。 I tried editing the systemwide /etc/.bashrc , and my users ~/.bash_profile. 我尝试编辑系统范围的/etc/.bashrc和我的用户〜/ .bash_profile。 Neither helped so far. 到目前为止都没有帮助。

All I need is to have /usr/local/bin as part of my $PATH. 我所需要的只是将/ usr / local / bin作为$ PATH的一部分。

I don't know if it is even possible, but I wonder why do you need this, ie do you need really to change your PATH env variable? 我什至不知道是否有可能,但是我想知道为什么您需要这样做,即您是否真的需要更改PATH env变量? Or it would be enough to you using this function and setting the variabile only for the created process? 还是使用此功能并仅为创建的过程设置可变性就足够了?

You can setup your Apache Server to run with your credential and resolve definitively the $PATH problem. 您可以将Apache Server设置为与凭据一起运行,并最终解决$ PATH问题。
However, you can also do this and it should works : 但是,您也可以这样做,并且应该可以:

<?php
putenv('PATH', getenv('PATH') . ';/usr/local/bin');
var_dump(getenv('PATH'));
?>

The modification of $PATH will still available only the duration of your PHP execution, there are other ways to set environment variable permanently $ PATH的修改将仅在PHP执行期间可用,还有其他方法可以永久设置环境变量

Hope that helps :) 希望有帮助:)

This may not be well received, but I have been in your spot and have come close to throwing my machine across the room trying to properly set the PHP path for MAMP in OSX. 这可能不太理想,但是我一直在您的位置,几乎把我的机器扔到整个房间,试图为OSX中的MAMP正确设置PHP路径。

I started using Vagrant and developing from a VM, and found it to be way easier, especially if you want to change languages for other projects. 我开始使用Vagrant并从VM进行开发,发现它变得更容易,尤其是当您想更改其他项目的语言时。 Trust me, it will save you time in the long run. 相信我,从长远来看,它将节省您的时间。

  1. Download VirtualBox 下载VirtualBox
  2. Download Vagrant 下载无业游民
  3. Select what type of box you want via PuPHPet 通过PuPHPet选择想要的包装盒类型
  4. cd into the puphpet directory and run vagrant up (may take a while!) cd进入puphpet目录并运行vagrant up (可能需要一段时间!)

The inital setup will take a little bit of time, but be very fast moving forward and makes it really easy to share environments with others. 初始设置将花费一些时间,但是前进的速度非常快,并且非常容易与他人共享环境。

Cheers 干杯

EDIT: I think its a very real solution for the future, but for now what worked for me was adding: export PATH=/usr/local/php5/bin:$PATH to my .bash_profile on OSX Yosemite. 编辑:我认为这是对未来非常真实的解决方案,但现在对我export PATH=/usr/local/php5/bin:$PATH是添加:在OSX Yosemite上将export PATH=/usr/local/php5/bin:$PATH到我的.bash_profile I believe the folder structure changed in Yosemite. 我相信优胜美地的文件夹结构发生了变化。

I know this is an older post, but this helped me, (doing this with Ampps, not MAMP, but it should work the same) 我知道这是一篇较旧的文章,但这对我有所帮助(使用Ampps而不是MAMP进行此操作,但效果应该相同)

From here 这里

Create a variable with the path to your PHP binary (in terminal) 使用您的PHP二进制文件的路径创建一个变量(在终端中)

they recommend 他们推荐

export AMPPS_PHP=/Applications/AMPPS/php/bin

mine was export AMPPS_PHP=/Applications/AMPPS/php-7.1/bin 我的是export AMPPS_PHP=/Applications/AMPPS/php-7.1/bin

then just 然后就

export PATH="$AMPPS_PHP:$PATH"

Test it out with which php or php -v which phpphp -v测试一下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM