Console php version diferent to MAMP on OS X - php

I have created a .bash_profile in my home and now it contains the following two lines:
export MAMP_PHP=/Application/MAMP/bin/php/php7.2.7/bin
export PATH="$MAMP_PHP:$PATH"
But the php -v command in the terminal still shows a different version to MAMP. I already restarted both the terminal and MAMP as well.
Any idea?

Related

How to check php version in MacOS sierra?

I have mac os sierra machine. When I start a php project in vs code, I get the following warning
language server needs php 7, and the version found is 5.6.27.
So I used homebrew to upgrade to version 7 and confirmed it from the terminal. I am also running mamp which show version 7.
But in the terminal of vs code the php version is still 5.6.27. So I am bit confused?
I changed the value of php.validate.executablepath in settings.json in vs code from usr/bin/php to usr/local/bin/php, but still vs code terminal showing the older version (viz. 5.6.27)
This is because VM Code still checking /usr/bin/php directory which is php5
You have to configure the path to the PHP executable in the user settings file.
Follow the following steps to change it
Go to File > Preferences > User Settings > Settings.json
Change the value of php.validate.executablePath according to the installed
directory of php7.
"php.validate.executablePath":
"/Applications/MAMP/bin/php/php7.0.14/bin/php"
Relaunch VM Code
If the problem remains same, then add the path to PHP7 to your environment variables, run where php and php --version to verify. To add path in your macos sierra do the following:
Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/user/local/bin:$PATH
Hit ESC, Type :wq, and hit Enter.
In Terminal run source ~/.bash_profile
In Terminal, type in which php again and look for the updated string.
If everything went successful, it should output the new path to MAMP PHP install.
In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short)
To find out what version you're using, upload a php file to your server containing the following code...
<?php
phpinfo();
?>
It will tell you at the top of the page.

exec() using different php version

I'm using Mac OS X (10.11.6) with MAMP PRO 3 and PHP 5.6.10. I've setup the PATH in .bash_profile and everything looks fine.
When I do which php in the terminal I get the following correct path:
/Applications/MAMP/bin/php/php5.6.10/bin/php
Now I'm trying to execute an exec-command with PHP along the lines of the following example:
exec('which php');
This returns /usr/bin/php and therefore is wrong, I want it to use the other version too.
My MAMP related things from .bash_profile:
export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH
export PATH=/Applications/MAMP/Library/bin/:$PATH
What am I missing?

How to run mysql commands from terminal on a MAMP install?

I just installed mamp (xampp) from the mamp.info page and it is working on my mac (both apache, php, phpmyadmin, and mysql). The only problem is when i try to run
mysql -u root -p
Which connects to mamp from the mac os terminal, i get a command error. I have installed and uninstalled mamp and xampp for mac multiple times to no avail.
I am following this tutorial; http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app and i can't get past a certain part because i don't want to use php admin, and i think it'd be cool to use it from the terminal.
My question; how do i configure mamp or xampp for mac to work from the terminal?
Put this at the end of your .bash_profile script (create it if it doesn't already exist):
export PATH=$PATH:/Applications/MAMP/Library/bin

trying to use MAMP's PHP, but `which php` always returns native OSX version?

I want to use MAMP on my OSX box as I am learning Laravel development.
I have added the following line to ~/.bash_profile:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
I restarted terminal, restarted MAMP, but when I run which php the result is still /usr/bin/php.
Any tips? Thanks!
Your path can be changed, while the default OS response to the which command remains unchanged.
Example:
which php
/usr/bin/php
php
bash: Applications/MAMP/bin/php: No such file or directory
Run this command:
echo "$PATH"
[NOT a complete answer]

Upgraded to PHP 5.5 on mac - having to load PATH into terminal each time

Last night I upgraded to PHP 5.5.3 using http://php-osx.liip.ch/ on my new Macbook. I have OS X v10.8.5
Each time on launch terminal or iTerm, I have to put PATH=/usr/local/php5/bin:$PATH into the terminal to get it to properly set the path. Why?
I did put the same path into ~/.bash_profile and ~/.profile.
Running phpinfo in the browser, without touching terminal, does show PHP 5.5.3.
Open terminal and type:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
5.5 is a PHP version (if you want install a specific version), then check if it works:
php -v
In ~/.bash_profile add export PATH=/usr/local/php5/bin:$PATH
My ~/.profile is currently empty.
Now in terminal do
source ~/.bash_profile
Try php -v.
I've restarted terminal a few times with the correct results. Both phpinfo() and terminal php -v show PHP 5.5.4.
Hope this helps.

Categories