setting "$PATH" variables for PHP in AMPPS (OSX) - php

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.

Related

Problems setting PHP exec path in MAMP after update to El Capitan

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

which is the environment variables route for cakephp 3?

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.

How to repair wamp server without re-installing?

After making changes in php.ini by uncommenting
extension=php_openssl.dll
My Windows-8 system got shutdown due to power failure and later i use to get this error when i try to start wamp server
Later visiting some link i added the below code to wampmanager.ini file as it was empty
Now the first error got fixed and now throwing this error mentioned below:
Later i also installed visual c++ 2008 to fix this error but unsuccessful. I have many important databases which i have not taken back up also. I am trying to repair this wamp server without re-installing. Can anybody please assist me with this.
Thanks in Advance
go to the wamp/scripts folder
open console
run:
php refresh.php
this should recreate wampmanager.ini
(requires wampmanager.tpl file in wamp folder.
taken from http://sourceforge.net/p/wampserver/feature-requests/10/#750b)
This document may help you How to uninstall WAMPServer without actually uninstalling it
The idea is that you uninstall your current version without actually running the unninstall and without actually deleting any files from your existing install.
You then rename the current wamp folder and then install the same version of wamp, make sure it works, and then copy all your sites and databases to the new installed wamp. If you install exactly the version of WAMP you have currently then you can copy the whole of the .../mysqlx.y.z/data folder and all you databases and users should be there on the new install.
This gets over whatever damage was done to your existing install. You may need to edit the php.ini and httpd.conf to match your existing configuration. I suggest you do not do a straight copy of either of these files as that may just get you to where you are now.
Fixed by installing wamp again into the same directory by renaming the older wamp. I just replaced wampmanager.ini file of new to the old one. Earlier it was just a little piece of code i pasted in wampmanager.ini file. But now it is a big one which fixed this issue. Thanks a lot for you guys, your suggestions saved my time. I did not change anything with php.ini also.
Backup all YOUR databases in SQL format and store the backups somewhere safe.
Stop All Services.
Remove the Apache Service.
Remove the MySQL Service.
Exit WAMPServer.
Rename your current \wamp folder to \wamp_old (This is your backup. DONT FORGET THIS STEP)
To all intents and purpose, you have uninstalled WAMPServer now.
7. Download and Install the new WAMPServer version
(32bit is recommended, 64bit is only for geeks and 64bit PHP is not yet fully converted to 64bit)
Change NOTHING! Check it works in its out of the box state.
Clear your browser cache ( CTRL+F5 ) to avoid any funnies with cached content.
Run localhost
Run phpMyAdmin (If asked for a Username and password; username = root / password = (nothing, leave this blank)
Run \wamp\www\testmysql.php. you will need to edit the file and change the "mysql_connect('127.0.0.1', 'root', '')"
If you want to bring some/all of your old versions of Apache/PHP/MySQL into the new WAMPServer
(Remember, one of the big advantages in WAMPServer is the ability to switch between versions of Apache/PHP and MySQL)
Apache: copy \wamp_old\bin\apache\apachex.y.z folder to \wamp\bin\apache\apachex.y.z
PHP: copy \wamp_old\bin\php\phpx.y.z folder to \wamp\bin\php\phpx.y.z
MYSQL: copy \wamp_old\bin\mysql\mysqlx.y.z folder to \wamp\bin\mysql\mysqlx.y.z
To tell WAMPServer about the old version of Apache/PHP/MySQL you just copied across run a "refresh",
right click the wampmanager icon -> Refresh
Give it a few seconds to go find all the new versions.
Compare your old configs with the new configs, move over any of your local change/requirements.
Remember, config parameters change between versions of Apache/PHP/MySQL !
Make sure your old changes are still required, valid, legal. ( Check the upgrade notes provided by all 3 software providers )
If it all goes horribly wrong. Check the bottom of this Doc to see how to unwind all these changes easily if you get problems.
help you
I have had the same issue. I am working with WAMP 2.5 version. The content of "wampmanager.ini" is OK but it's possible that the php path is wrong. Check folders of section [StartupAction], in my case my php version is "php5.5.12". Surely the error message "The directory name is invalid" was for this.
In win10 you can just right click on the wampmanager.ini file in the root and select Restore Previous Version, then just choose one from a few days ago when it worked.
i have similair issue in the morning and searched SO and other forums but none of the solution worked for me.
It was
syntax error on line number 561 (due to MariaDB)
After checking all wamp installation for MariaDB, i find out that file at root: wampmanager.conf contain lines about MariaDB. I removed all of those and then restarted wamp. It worked like charm!
Rename the wamp folder, you can just add a 1 or 0 to somehing like wamp641 then
re-install wamp server
3.copy paste the mysql and project folders from Bin and WWW respectively from the renamed wamp folder to the newly created folder after installation so that you dont loose any database and project files from your previous projects.
4 start your wamp and it should work well.

FuelPHP "invalid data source name" error

I'm trying to set up a FuelPHP app, and I've run into a puzzling problem. Every time the app tries to connect to the database, I get the following error:
Fuel\Core\Database_Exception [ Error ]: invalid data source name
I've set FUEL_ENV to "stage" in Apache's VirtalHost configuration and the database credentials in fuel/app/config/staging/db.php seem to be correct: I can log in to PhpMyAdmin using the same username and password. I'm stumped as to what else to try - any advice would be much appreciated.
In case it helps, I'm using FuelPHP 1.4 on an Amazon EC2 instance running Ubuntu 12.04 LTS on which I've installed MySQL and PHP via apt-get. I have another app (on another instance) running an older version of FuelPHP (1.2.1) which runs with no problems.
Incidentally, this question is probably closely related to this one, but I'm asking it as a separate question because the problem I'm having is not limited to the command line.
Ok, this has taken far too long to get to the bottom of, but it turns out to be simple to fix: for some reason, in FuelPHP 1.4 the stage environment's config directory is called staging (in previous versions it was stage).
I don't know whether this is a directory naming mistake, or whether this is a new name and something somewhere in FuelPHP hasn't been updated to use it, but I found changing the directory's name to 'stage' fixed the problem.
I had the same issue when running unit tests with FuelPHP's oil utility. If you're running into this issue, it most likely is a configuration issue.
To debug, somewhere in the code that isn't working put something like the following to see what environment FuelPHP is trying to use:
<?php
echo "env: " . Fuel::$env;
exit;
In my case, it showed it was trying to use the 'Test' environment. Since I didn't have a 'test' folder in my app's config folder, it was failing.
In most versions of FuelPHP, however you have the Fuel::$env set in your .htaccess file will work throughout all versions of FuelPHP. However in older versions, you may run into this issue.
You can either edit the bootstrap.php file and manually set the FuelPHP environment how you want, or setup the environment that it's trying to use.
Apache web server: SetEnv FUEL_ENV DEVELOPMENT Hope this helps someone
For those of you who none of this worked make sure of two things
there are multiple db.php files /fuel/app/config/development/db.php. check environment as #Chad Hutchins mentioned and double check the username and password is correct
Make sure /var/mysql/mysql.sock exists. In my case I was using /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock so i needed to create a symlink. Followed the instructions here
Hope that helps someone

Windows XP path problem

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.

Categories