Composer use MAMP PHP Version - php

I'm trying to install a package via Composer that requires PHP 5.6.0. My MAC is running PHP 5.5.31 but MAMP runs PHP 7.0. The package will not download because of the PHP requirement is not met since it's looking at my macOS version, not the version I actually use with MAMP. How can I get around this?

MAMP's PHP is located here:
/Applications/MAMP/bin/php/php7x.x/bin/
The default OSX PHP is located in
/usr/bin/php
/usr/bin is in PATH variable by default.
When you want OSX to use the MAMP version instead, you need to add /Applications/MAMP/bin/php/php7.x.x/bin/ to your PATH variable.
Simply edit ~/.bash_profile in your terminal and type
vim ~/.bash_profile
if you cannot find ~/.bash_profile then you have to create one with
touch ~/.bash_profile
and add the following line to end of the file:
export PATH=/Applications/MAMP/bin/php/php7.x.x/bin/:$PATH
You just have to look at the correct version of your MAMP's php and replace the x.x from the example above with that correct number. (e.g. 7.0.2)
If that went fine, relaunch your terminal.app and do php -vagain. Now you have to see the new version.
After that try to install the composer package again! Good luck
Help source: how-to-override-the-path-of-php-to-use-the-mamp-path

This was easy to me:
First backup system php sudo mv /usr/bin/php /usr/bin/~php
Then crate a symbolic link from /Applications/MAMP/bin/php/phpX.x.x/bin/php to /usr/bin/php using this: sudo ln -s /Applications/MAMP/bin/php/phpX.x.x/bin/php /usr/bin/php. Now you have your mamp php (with its config) available everywhere.

If you type 'which php' into Terminal it'll show you where it's looking for PHP. I'm guessing there are 2 different versions of PHP installed into different directories. In which case you might be able to use a bash script to set the correct path to the PHP version you want?
I've had similar issues on my Mac where I've installed software like git, but it's looking elsewhere for it (e.g. the version bundled with Xcode)

Related

PHP 7.0 installed, but version doesn't change

I'm trying to install PHP 7.0, which works. But when I check my php -v in the cmd, it still says 5.5.36.
I tried it via php-liip, homebrew, install manually and via cmd. Nothing works. When I change version of PHP in MAMP (which I work with to try and install composer in a directory, that I need PHP 5.6 or higher for) i still doesn't matter.
The PHP 5.5 you're seeing was installed by Apple and is a default on your computer. It was installed at /usr/bin/php.
All of the installers you've used will not overwrite Apple's default installation - they will instead opt to create their own directories or use /usr/local/bin/ instead (thus the PHP interrupter would be installed at /usr/local/bin/php). In other words, you almost certainly have multiple php's ready to use right now. The next thing you need to do is tell bash (the default terminal/cmd on a Mac) to use the newly installed PHP interrupter.
When you run $ php on your command line, bash checks for an executable file on each of paths stored in the PATH environment variable. Once it finds one, it decides that that executable is the one you're looking for and runs that program. As of now, it's finding Apple's PHP 5.5 before it finds your fresh install of PHP 7.0 - assuming it finds PHP 7.0 at all.
You can fix this by updating PATH to check wherever PHP 7 is installed first. Instructions to do so can be found on SuperUser.StackExchange:
How should I set the PATH variable on my Mac so the Homebrew-installed tools are found?
To change php version in Ubuntu, try to use this comand
sudo update-alternatives --config php
and then select version what you need

Wrong PHP version after installation (OSX)

I am running OSX El Capitan which comes (if I am not wrong) with PHP 5.5.
So I updated my PHP version using this Terminal command:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
And from the docs :
php-osx doesn't overwrite the php binaries installed by Apple, but
installs everything in /usr/local/php5. The new php binary is
therefore in /usr/local/php5/bin/php.
You can also adjust your PATH do include that directory, eg. write
into your ~/.profile file the following
So I did what have been suggested, but still, my php version (shown by php -v) is 5.5 rather than 5.6.
What I am missing here?
After editing ~/.profile or ~/.bash_profile you either have to restart your terminal or do source ~/.profile so the changes take effect immediately.

Lion Server updating php from 5.3 to 5.4

I am trying to update our PHP version (Current: 5.3.15) to the latest 5.4.16 i used this link for my Lion Mac PHP Install and all worked well.
So then i went onto our Mountain Lion Mac Server and did the same but its still showing via phpinfo page as 5.3.15 same if i do a php -v via the terminal.
i understand that this install places it into the usr/local area whereas i believe the server is getting the php etc from /usr/bin/php and not the local.
So how ca i update the main php scripting and not the local or link up the server to use the local updated version?
Replace the default location with a link to the new version:
sudo mv /usr/bin/php /usr/bin/php.orig
sudo ln -s /usr/local/bin/php /usr/bin/php
What does your $PATH look like on the command line? You need the path to your PHP binary in /usr/local to come before the path to the system's default installation of PHP.
One alternative would be to install PHP in the same place as the default version, thus overwriting it.
I'd be wary of only making a symbolic link from /usr/bin/php to your local version of PHP. This might work for executing PHP scripts, but when it comes time to compile custom extensions and what not, it could confuse phpize and mess up your build process.

Terminal displays wrong php version (Snow Leopard)

Need to downgrade php to 5.2.x, so I followed this tutorial:
http://andreys.info/blog/2010-03-25/compile-php-5-2-on-osx-10-6-snow-leopard#comment-631
I'm on snow leopard 10.6.4, with xcode installed.
So I compiled php5.2.x and completed the tutorial. phpinfo() loaded within the browser at htp://localhost says 5.2.x, Great!! But, Terminal command "php --version" says 5.3.x ??
While compiling/installing php5.2.x, the new module file replaced the php5.3.x module here:
/usr/libexec/apache2/libphp5.so
So where is Terminal getting 5.3.x from?
Do I have two php versions being loaded?
Should I even care?
For a more direct solution to the problem:
Rename the OLD version of PHP
sudo mv /usr/bin/php /usr/bin/php5424
Create a Symbolic link for your new version of php so it can live in /usr/bin
sudo ln -s /usr/local/php5/bin/php /usr/bin/php
Check using which php. This should tell you which is being used.
Yes, looks like you have two installed at different locations.
Yes, mind what's being used where. Having multiple versions is absolutely valid (at least on a development or testing system) but you always should be aware of the versions being used.

php related error in linux terminal while setting up symfony framework

i am trying to setup a new symfony framework project on ubuntu by following the documentation. But all the commands mentioned in the docs starting with 'php' give out the following error.
The program 'php' is currently not installed. You can install it by typing:
sudo apt-get install php5-cli
bash: php: command not found.
But php is installed and running on the system! How do i get past this error ?
Thanks in advance.
There are several different PHP packages; probably the one that is installed is the PHP module for Apache, not the command-line (CLI) version invoked as php.
Just run the command like it says, and you should be fine.
Is php on your path? (does it start if you just type in 'php' at the prompt or do you need to specify a path?)
If so, then its possible that the path is hardcoded to look elsewhere for your PHP executable. Try grepping the scripts to see where its looking.
If php is NOT on your path then try adding it, e.g. if php is in /usr/local/bin (and /usr/local/bin is not currently on your path)
export PATH=$PATH:/usr/local/bin
HTH
C.

Categories