For something that should be so simple, I'm finding it maddeningly difficult to set the path that PHP exec() commands use under MAMP on a Mac running El Capitan.
I need the solution to use environment variables rather than (for example) PHP's putenv() or a hardcoded "PATH=foo && ", as this code will be used on different servers that each may use a different path. I had it working fine on Yosemite (though, to be honest, I can't remember what finally worked), but when I upgraded to El Capitan the path was reset.
I've tried the following, and have restarted the computer after each just to be entirely sure that Apache's path was being reset:
Added to path in /etc/paths and /etc/paths.d
Added export PATH=$PATH:/opt/local/bin to MAMP/Library/bin/_envvars
Even set path in /System/Library/LaunchDaemons/org.apache.httpd.plist after disabling SIP to make it possible.
Edit to add: Also tried a symbolic link to somewhere in the default path, but LaTeX, for example, really needs to live on the path.
After each of these, the path (as indicated by a "exec('echo $PATH', $output);" command in the PHP) remains the same:
\/usr\/bin:\/bin:\/usr\/sbin:\/sbin
I'm at wit's end. If anybody's managed to set the path on a similar setup, I'd love to get input on how it was done.
Thanks!
On Mavericks it worked like this:
- Stop MAMP
- Rename the file /Applications/MAMP/Library/bin/envvars_ to /Applications/MAMP/Library/bin/envvars (without underscore).
- Add these two lines at the end of the renamed file:
PATH="$PATH:/additional/path1:/additional/path2"
export $PATH
- Start MAMP and have a look into phpinfo() Output
Related
A while ago, I successfully configured Atom to beautify my PHP using php-cs-fixer, but now I need to go through the same process on another Mac and can't remember exactly how I did it.
As a front-end dev, I'm not a PHP expert, but I understand that the Atom plugin is merely the middleman facilitating the actual fixing using php-cs-fixer, which, by default, it doesn't have access to. Once I installed the fixer, I had to add its location to my PATH variable. The confusing part is that I don't have the fixer installed via Atom (checked ~/.atom/packages) nor Homebrew (confirmed with brew list), however, the file is present in /usr/local/bin. If I move it, Atom returns the original error, so it's definitely using this file:
See https://github.com/FriendsOfPHP/PHP-CS-Fixer for program installation instructions.
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable.
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=php-cs-fixer&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'php-cs-fixer'. The program may not be installed.
at PHPCSFixer.module.exports.Beautifier.commandNotFoundError (/Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:204:14)
at /Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:304:22
at tryCatcher (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:687:18)
at Async._drainQueue (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:148:10)
at Async.drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
at process._tickCallback (internal/process/next_tick.js:103:7)
which php-cs-fixer returns /usr/local/bin/php-cs-fixer and my PATH variable currently contains /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ourcore/.atom/packages/php-cs-fixer.
I guess my questions are, how is the fixer working if the PATH variable seems to be pointing to it in a different location, and how did it end up where it is? Does the location in my PATH matter at all, or does the Atom plugin know to look in /usr/local/bin? I just want to fully understand the entire process before repeating it.
EDIT: On further testing, I removed the Atom directory from my PATH and it didn't affect the plugin, so then I copied the file into the same directory onto the second Mac and it ran without issue, without needing to edit the PATH. Does the fixer file someone inform the OS?
Well first test "which php-cs-fixer" or "where php-cs-fixer" (depending on what os you're running) and if nothing is returned in the terminal then there actually is something wrong on the installation and the best thing to do is to manually install it.
Head to https://github.com/FriendsOfPHP/PHP-CS-Fixer and download it from there and follow the installation steps, after that it should all be good
I recently installed a cakephp with composer to learn about framework use, and trying the bookmarks tutorial, but I get stucked in the checking your installation where you have to open the command line AKA cmd, and writing bin\cake.
It replies back: the system cannot find the path specified.
I've seen some information about how to set up the path variables but I'm guessing it's for version 2+ because apparently the cakephp 3 doesn't have a LIB folder like such:
YOUR_CAKE_DIR/lib/Cake/Console/
Any ideas on how to fix this?
Thanks
best regards!
***************UPDATE**********************
well, I've finally fixed the problem, the path I used for the cakePHP 3 instalation was:
c:\xampp\htdocs\caketest\bin
so I assume that If you aren't using xampp, it should point at the end to: cakeinstallation\bin...
my problem was that I always typed bin\cake but actually all I had to do was type only:
cake
you can read more information in here
bin\cake shouldn't require any special path settings other than being in the correct directory. However, you should make sure that php-cli is on your system's PATH. Depending on how you install PHP it could be in any number of places, but if php -v doesn't output the version of PHP you installed, you'll need to find where your installer put PHP and then setup the PATH environment variable.
With your example, AFAI remember the working directory they were executing cake binary was the parent of "bin" folder, in your case "caketest". I am talking without trying it (I dont have an environment close) you should use:
c:\xampp\htdocs\caketest> "bin/cake"
Watch the quotes. I think they are the main reason of that "the system cannot find the path specified."
I am supossing you are under windows (I saw xampp written in your post) and probably the xampp installation has already added the php folder in the PATH environment variable.
I have a question about setting "$PATH" variables for PHP scripts in AMPPS
(On OSX 10.10 Yosemite).
The PHP in AMPPS seems to run as my user "danny", however the $PATH it sees
is different. Here's what I see from my terminal:
Dannys-MacBook-Air:AMPPS danny$ echo $PATH;
/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"
I tried doing "putenv()", tried doing "shell_exec" with a different $PATH,
I tried doing SetEnv in .htaccess and in the Apache config file. I tried
editing the systemwide /etc/.bashrc , and my users ~/.bash_profile. Neither
helped so far.
All I need is to have /usr/local/bin as part of my $PATH.
I know this is an older post, but this helped me, (doing this with Ampps, not MAMP, but it should work the same)
From here
Create a variable with the path to your PHP binary (in terminal)
they recommend
export AMPPS_PHP=/Applications/AMPPS/php/bin
mine was 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
I don't know if it is even possible, but I wonder why do you need this, i.e. do you need really to change your PATH env variable? 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.
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
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.
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. Trust me, it will save you time in the long run.
Download VirtualBox
Download Vagrant
Select what type of box you want via PuPHPet
cd into the puphpet directory and run vagrant up (may take a while!)
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. I believe the folder structure changed in Yosemite.
I assume that MAMP environment variables can be set in ~/.bash_profile, but it seems that setting them there does not always take effect right away. For instance, I just set a variable in my .bash_profile and have tried restarting MAMP servers, restarting MAMP itself, and even logging out of my computer and nothing seems to work. The variable is still not accessible from within my environment. Is there another way to set MAMP env vars that I'm missing or is there a cache that I need to clear?
Thanks in advance.
You can also set PHP environment variables in MAMP Pro (not available in MAMP) in the additional parameters for <VirtualHost>: section found in the extended tab of the hosts settings panel.
Screenshot is from MAMP Pro v 3.0.3
MAMP will load the contents of /Applications/MAMP/Library/bin/envvars into its environment variables when starting apache. So you can edit the file and add:
MY_VAR="foo"
export MY_VAR
Then access that variable like so:
echo $_ENV["MY_VAR"];
prints:
foo
Update for OSX Yosemite:
rename envvars to _envvars
See: MAMP Pro 3.05 on Mavericks updated to Yosemite - Apache does not start
You can set your environment variables in Apache configuration...
/Applications/MAMP/conf/apache/httpd.conf
SetEnv MY_VAR theValue
SetEnv ANOTHER thisIsTheValue
MAMP is looking for "/Applications/MAMP/Library/bin/envvars", if the file doesn't, simply create it and add your environment variables.
I'm assuming you're talking about a local server?
I've noticed, if you look at the processes that apache can have multiple instance running that you might need to check. If they are, quit out of them individually, as the restart won't take the new changes until all instances are restarted. Something to try.
If you still can't get your environment variables:
you may need to edit your real httpd.conf in
~/Library/Application Support/appsolute/MAMP PRO/
instead of
/Applications/MAMP/conf/apache/
Also you may need to use getenv() instead of $_ENV
But it doesn't work with El Capitan. You should disable System Integrity Protection.
original
My Environmental Variables (& I crosschecked every possible place in the Registry) show my PHP include path as: "C:\PHP\" --and PHP (5.2.9-2) works fine on the system, so that is correct. However, running
ini_get("include_path")
shows the path as "C:\PHP5\". This causes problems with PEAR, etc. I've searched the system (i.e. php.ini files, httpd.conf, & everywhere else I can think of--there are no .htaccess files) & can find nothing that points at PHP5. Where in the world is this coming from??
Try searching for the literal PHP5 using a grep search tool (like windows grep http://www.wingrep.com/) it will take a while, but I think it's the best approach after you've checked all config files and environment variables.
Cheers
If you run a script with a call to phpinfo() PHP will tell you where the values come from:
<php
phpinfo();
?>
The top table will tell you what php.ini files it's reading and you'll find the value of the include_path directive in the Core table.
Something could be setting it using ini_set.
Or, after running the aforementioned grep on the whole system, you can try these:
Debug PHP to see what causes this.
Use Filemon from Sysinternals to see what files PHP is accessing.
This isn't really an answer to your problem however if you install WAMP or XAMPP you can usually avoid all of these annoying configuration issues.