Upgrading PHP CLI version on mac - php

I just now bought new Macbook Pro for development purpose. I did a small research and install MAMP on Mojave OS for my current project but happen to see my PHP CLI version is 7.1.23 and was unable to upgrade, coming from Windows background I have a lot of experience in XAMPP. I found the MAC OS installer and did my in installation with latest version of PHP available. As I wanted latest PHP for my project.
Now when I see phpinfo(); through my XAMPP localhot I can see PHP version 7.3 but when I go to terminal I see the same old version. I tried updating the PHP using this link but no luck in updating PHP CLI version.
And in CLI
Help me out with this. Thanks.

Run this command:
alias php='/Applications/MAMP/bin/php/php7.2.7/bin/php'
and replace 7.2.7 with your version number.
This will only work until you restart the terminal, in order to keep this change when re-opening the terminal you need to do the following:
Open ~/.bash_profile with a text editor of your choice (eg. nano)
nano ~/.bash_profile
Go down to the bottom and add the line from earlier.
Add alias php='/Applications/MAMP/bin/php/php7.2.7/bin/php' to the bottom of the file. Of course you can replace 7.2.7 with the version of your choice.
Similarly we can do it for XAMPP, like this:
export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH

Related

MAMP PRO 6 command line shortcut not working

Hello and thank you for taking your time to read this! Now to get straight to the point, I am using MAMP PRO 6 for school and recently we had to install Composer through the terminal. Upon closer inspection php -v revealed that I am not using the MAMP's php version with Xdebug but rather the pre-installed php version that comes with macOS. I have enabled Activate command line shortcuts for the selected PHP version, pear & pecl but this is not working. I'm on the latest Big Sur update and looking for a possible fix.
MAMP PRO is working with the exception of command line shortcut.
Depending on the shell you use (bash, zsh, check your OS) just add "source ~/.profile" to your bash, zsh-or other profile. MAMP PRO 6 recreates the .profile when changing php versions.
Check the "composer"-link in the UI and everything should work just fine. Don't forget to start a new terminal session though. Otherwise the old configuration (with the old php and more) stays active.
~/.profile is not being read. You have to define a ~/.bash_profile, ~/.zshrc or something. In that profile that is read by the shell you put the "source"-statement.
The issue is that my .profile is not being loaded automatically , current workaround is doing source ~/.profile and then confirming the location and version with which php and php -v.
Update: This did it for me https://stackoverflow.com/a/56236178/14612433

Download and install the php mcrypt extension under windows 10

where can I download and how to install the mcrypt extension for php 7.1 (TS,VC14) under Windows 10 / 64 bit.
I need it for an akeneo project and this has dependencies using mcrypt (and not other extensions).
I haven't found the right extension dll for it.
Thanks for help.
This example is for PHP 7.4 installed by WAMP in Windows 10 (It will work for others versions if you manage to find the php_mcrypt.dll file for PHP version that you need).
Go to: https://windows.php.net/downloads/pecl/releases/mcrypt/1.0.3/php_mcrypt-1.0.3-7.4-ts-vc15-x64.zip
unpack and copy php_mcrypt.dll to C:\wamp64\bin\php\php7.4.0\ext
Include following lines in C:\wamp64\bin\php\php7.4.0\php.ini and C:\wamp64\bin\apache\apache2.4.41\bin\php.ini:
[mcrypt]
extension=php_mcrypt.dll
Restart Apache server
For other PHP versions you may find the php_mcrypt.dll file in https://pecl.php.net/package/mcrypt or in php windows binaries file: in PHP windows binaries files in ext/ folder https://windows.php.net/downloads/releases/
If you need this code run and it uses mcrypt I doubt if it really requires php 7.1
What might help you (however might not be recommended)
Install Wamp for windows link where you can easily switch between PHP 5 and 7
Wamp isn't ideal for custom php versions but I managed to add some "my-versions" if I did not find interesting ones on the list, you can switch versions by click on the icon at the icon try. left or right (check both ways)
check this link also
Much better in customizing your PHP would be Docker but it requires some learning curve instead of clickable Wamp. However with Docker you can do whatever possible to PHP where with Wamp you'll be always having some obstacles (mainly because of lack of resources how to do something, and specific Windows platform).
If you give up with Wamp, install Docker and run command:
docker run --rm -it php:5-apache php -r 'print_r(get_loaded_extensions());'
to check loaded extensions on php 7 with apache run
docker run --rm -it php:7-apache php -r 'print_r(get_loaded_extensions());'
to see if the php version has mcrypt installed and if not then installing it to docker image of php should't be a big deal (let know in comment if you need info bout that)
Here you have an official PHP image for Docker with description how to install extensions Dockerhub PHP image
Maybe this will help mcrypt-module-open
Best solutions is to install Linux. use a VM or the Windows Subsystem for Linux.
https://learn.microsoft.com/en-us/windows/wsl/install-win10

php --version Alias setting goes wrong on Mac

I am developing a PHP project. I am using Mac OS X now. To be honest, this is the first time developing a PHP project using Mac. I am a Windows. I installed PHP using Brew by running the following command.
brew install php
It gave me the php latest version, 7+. For my project, I need to use php version 5.6. So, I installed another PHP by running this command.
brew install php56
Up until this point when I enter "php --version" in the terminal, it is showing that I am using php version 7+. I found some solution to change php version and so I used one of them and run this command.
alias php='/usr/local/etc/php/5.6/php'
After running that command, when I type in "php --version" in the terminal, it is showing this error.
-bash: /usr/local/etc/php/5.6/php: No such file or directory
Now, I cannot use any PHP on my Mac right now. How can I fix that?

PHP (cli) version doesn't match XAMPP version I installed

Recently I installed XAMPP for doing local development on my Windows 7 machine. I honestly didn't think PHP was installed at all before hand. I installed the latest version of XAMPP and configured for php 5.6.24. I created some virtual hosts and everything seemed to work.
I was having an issue and I needed to confirm which version of PHP I was using so I opened up my command line and typed php -v. For some reason it is reporting I'm using PHP 5.4.25. The exact line is PHP 5.4.25 (cli) (built: Feb 5 2014 21:19:58)
I don't recall using this version (I had Visual Studio Community installed recently, is that related?). I don't understand either why my CLI is reporting one version, when XAMPP supposedly installed another version. Am I missing something? I need to run some gpm commands for the latest version of Grav CMS but when I do it says it required at least 5.5.9.
It is possible to have multiple versions of php installed.
You will want to ensure that you are executing the php-cli that came with XAMPP.
It sounds like you have another version of php installed and is in your PATH so that when you run php that version is loaded.
You can use the where command to find out what file is being loaded.
From the terminal type: where php
I am not a windows guy but there is a which command on linux. Apparently this is the command for windows. Here is a SO post about it:
Is there an equivalent of 'which' on the Windows command line?
Anyways, you may want to remove that php file and possibly create a symbolic link in its place for the XAMPP version of php-cli
If you remove/rename the file and the new php-cli is not in your path, you will probably get an error as the system will not know what php is.
The solution to this is to uninstall all the xampp's that are installed and then fresh install xampp with php version > 7.
Everything should work fine then.
What happened to me was that I had installed xampp two times. One
xampp on my C:// (version 5.6) and one xampp on my D:// (version 7.2)
When I did the command on my D:// xampp
php --version
It took the xampp php version from the C:// instead of the D://.

Apache and Terminal runs 2 different php builds, on Mac OS 10.8

Since Mac OS 10.8 had an old PHP version I had to install a never version of PHP. So I just compile PHP 5.4.13. Then I do a php -v on the terminal and it shows me that the new php version is running. But When I do a phpinfo from the browser it shows me the old PHP version which is PHP 5.3.x. This is even after creating a soft link to the new php build,
/opt/local/lib/php(old one) -> /usr/bin/php(new one)
Any ideas how to fix this issue?
I just ran into the same issue, wanting to try Laravel which requires mcrypt.
In a nutshell, I had been using the built-in PHP 5.3.26 that came with Mountain Lion, then some months later after I'd gotten more familiar with homebrew, I used it to install a newer version of PHP.
brew update
brew upgrade
brew install php53 php53-mcrypt ...
I put
<?php phpinfo();
into ~/Sites/info.php then went to localhost/info.php to see my Apache+PHP config. On the page, I saw this, under Loaded Configuration File:
/private/etc/php.ini
Then in Termninal, I ran this:
php -i | grep ini
which showed this output
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
Plus even more configs loaded as well ...
Additional .ini files parsed => /usr/local/etc/php/5.3/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.3/conf.d/ext-xdebug.ini,
/usr/local/etc/php/5.3/conf.d/redis.ini
The problem I had was that mcrypt was loading in the php cli version, but my Laravel test page wouldn't load giving an mcrypt extension not found error [1]
I used a diffmerge tool [2] to compare the original Apple php.ini in /private/etc/ to the one homebrew installed in /usr/local/etc/php/5.3/ and found there to be significant differences! So check carefully before trying this:
What I did next was to backup
sudo mv /private/etc/php.ini /private/etc/php.ini.apple
Then symlink the php.ini to homebrew's instead
ln -s /usr/local/etc/php/5.3/php.ini /private/etc/php.ini
Finally after reloading Apache
sudo apachectl restart
And mcrypt loaded, and now they're using a single config.
If you have another app on your localhost that breaks with the new config, just remove the symlink, and change it to the .apple version and restart Apache to revert back.
Laravel requires the Mcrypt PHP extension
https://sourcegear.com/diffmerge/
This might be a good reference:
how do i install php 5.4 on Mac OS X Lion?
There are some detailed instructions on upgrading PHP to 5.4, and also notes on how MacPorts can make it pretty painless.
I'm running OS X 10.9. I updated PHP to v5.5.8 and found that Apache was correctly running the new version but the terminal was still running the old one. After hunting around for a solution for a while, I eventually thought, "I'll give it a restart."
Bingo! Terminal and Apache are running the same version of PHP.

Categories