Which file in /usr/local/ shows the version of php on mac - php

I need to check the version of PHP in my folder /usr/local/php. My system Mac OS X 10.11.6 El Capitan.
The command from Terminal PHP -v is fine, but I need to go to that folder and manually search and open the file that shows PHP version. Please, help me on this matter. I am just learning, and I face difficulties with setting up PHP, so I do need to perform that check manually. Which of the folders and which file should I look for in the following list of folders inside the PHP folder:
bin
entropy-php.conf
etc
include\infor\lib
libphp5.so
php.d
sbin
share
var
Thank you very much!

just run php -v
e.g.
# php -v
PHP 5.6.10 (cli) (built: Jul 6 2015 14:28:54)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
If you want to know the version from within your code you can use:
<?php
echo phpversion();
if (phpversion() > 5.6) {
...
}

If you want to check manually just by looking into a file, one way is checking the php-config file inside the "bin" directory. You can find the version at top lines of the file.
If you're using the default php of your mac it's on /usr/bin/php-config.

Related

Configure CLI interpreter for PhpStorm on Mac

I have installed PHP from brew and it works just fine in VSCode, but in PhpStorm I am not able to configure the interpreter in order to debug my PHP code.
In the configuration file, it says "PHP not installed" with a red icon, and the executable path is empty.
I am trying to debug just code, not a web page, so there is no need of Apache Server or other for now.
When executing php -v on terminal, I get:
PHP 8.0.17 (cli) (built: Apr 5 2022 22:43:04) ( NTS ) Copyright (c)
The PHP Group Zend Engine v4.0.17, Copyright (c) Zend Technologies
with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies
which tells me that this installed correctly.
As per PhpStorm documentation you have to point to PHP executable there (which means: provide the full path). Just having php may not be enough.
Open your OS terminal and type which php (or it could be where php; this depends on the OS used). It will show the full path to the executable that gets executed when you run php in that terminal.
If you have more than one PHP version installed and want to use non-default PHP installation/version then use the path for that specific version.
Copy that full path from there (if there are more than one path then use the top most or the most desired one) and use it in the "PHP executable" field of the PHP Interpreters screen in PhpStorm.

How to make the right PHP version on my terminal? [duplicate]

I have a problem with PHP which is call through bash command "php":
In bash:
php -v # PHP 5.3.17
/usr/bin/php # PHP 5.3.15
I want secondary PHP version 5.3.15 as mainly, because in this version I have correctly installed extensions etc.
How can I set /usr/bin/php as main -> I want when call "php -v" return my 5.3.15 version.
Execuse my bad English, I hope that you understand.
Thank you so much.
I have Mac OSx Lion
Another way without changing the original php file / link is if you edit your .bashrc file as follows (works with other commands as well):
Open your Terminal / Commandline and type in:
vim ~/.bashrc
Then press "i" to get into edit-mode (if there shows up a problem before that, because of a swap file, then press "E" to edit the file anyway)
Add the following line (change the path as needed):
alias php="/Applications/MAMP/bin/php/php5.4.10/bin/php"
Press "ESC" and type in ":wq"
If you need the php-alias to work right out of your current shell-session, then you have to use the following command (that's optional, so only if u r continuing to work in your current shell):
source ~/.bashrc
That's it, no change in the /usr/bin folder needed, and u can export your bashrc file / settings to any other linux / bsd like system if needed without even touching your OS /usr/bin files. You can also add new aliases for different php versions, aliases like "php52", "php53", "php54", etc. for testing purposes or whatsoever.
Have fun,
ioCron
OS: OSX Yosemite
Just sort out a similar issue by vim ~/.bash_profile
export PATH=/usr/local/bin:$PATH
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
Make sure the order is correct. Put export PATH=/usr/local/bin:$PATH before export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
/usr/local/bin contains the mac default php.
Hope this helps.
For brew users, you might not need php55 if you already have 54 - but regardless you should probably run these commands
$ brew install php54 php54-xdebug php54-mcrypt
you can substitute 54 with the latest number if you want. last i checked it was on 56
then based on some of the comments above you should run:
$ php --version
it will probably display:
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
if it does, then change your .bash_profile like some of the other commenters
my brew instance (i think its default) lives in
/usr/local/Cellar
/usr/local/bin
as things get installed using brew, they get put in Cellar and linked through the bin. but in this case we need to override the php
$ sudo nano ~/.bash_profile
mine kinda looks like:
PATH=$PATH:~/bin
PATH=$PATH:/usr/local/bin
PATH=$PATH:/usr/local/sbin
PATH=$PATH:/usr/local/Cellar/r/2.15.1/R.framework/Versions/Current/Resources/li$
export PATH
which means that it already has access to the /usr/local/bin - but i use the alias to specify
by adding this line, near the bottom:
alias php="/usr/local/bin/php"
save and close the terminal window, open up another one, and it should show something like:
$ php --version
PHP 5.4.27 (cli) (built: Apr 24 2014 17:16:35)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans
You should look up the path and check all directories in the path for a symlink to the wrong php version.
Then you can remove that symlink and replace it with a link to the correct version.
You can also use find to see all instances:
$ sudo find / -name "php"
I would recommend you to install php through "Mac Ports".
You have multiple versions of php installed.
With the cli command "which" you can:
DESCRIPTION
The which utility takes a list of command names and searches the path for each executable file
that would be run had these commands actually been invoked.
So read the man pages of the cli command "which".
DO this from your cli:
which php
and then you will see where is located your php executable. What i would recommend you is to replace your php executable for a symbolic link to your /usr/bin/php.

How to change preloaded php version to MAMP in Mac/OSX

I am using Mac/OSX for the first time and I have installed MAMP and set PHP Standard Version as 7.1.6 but when I have run php -v command in the terminal I am getting below details:
PHP 5.6.30 (cli) (built: Feb 7 2017 16:18:37)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
Can you please guide how to use 7.1.6 version instead of 5.6.30.
Thanks.
Instructions to Change PHP Installation
First, Lets find out what version of PHP we're running (To find out if it's the default version).
To do that, Within the terminal, Fire this command:
which php
This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be (Assuming you've not changed it before):
/usr/bin/php
Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/MAMP/bin/php/php7.1.6/bin
To do this, We need to edit the .bash_profile and add the MAMP version of PHP to the PATH variable.
Follow these simple steps:
Within the Terminal, run
vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/Applications/MAMP/bin/php/php7.1.6/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 was successful, It should output the new path to MAMP PHP install.

error upgrading php in mac

I am running OSX El Capitan (version 10.11.6).
I had php 5.5 installed.
Phpunit requires php5.6 and more so I tried to upgrade my php to 5.6. I couldn't do it so I gave php7 a try.
I followed these guides:
https://coolestguidesontheplanet.com/upgrade-php-on-osx/
https://php-osx.liip.ch/
Mac upgraded PHP to 5.6, but CLI php -v get 5.3.28?
My current output with php -v is :
PHP 7.0.12 (cli) (built: Nov 1 2016 10:21:11) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
Funny thing, my output with a phpinfo(); when called from somewhere inside a Symfony project, is still PHP Version 5.5.36
Any ideas??
Terminal uses a different PHP than a HTTP server in browser. You can check what PHP you're using in CLI (command line interface) by this terminal command:
$ which php
I don't know if you use any AMP stack (like MAMP). They include their own PHP, so you need to update them in order to have a different PHP version in browser.
Maybe you can use this trick to determine what PHP versions you use in browser / CLI: Find the php.ini path in your phpinfo() output and compare it with this terminal command:
$ php -i | grep php.ini
It's always a good idea to use the debug URL to troubleshoot your Symfony projects; to use this, simply append:
app_dev.php
For example if your route was like http://myhome/, then you would use:
http://myhome/app_dev.php
Then on the bottom of your browser you will have the Symfony debug bar. In the bottom right corner, the version of Symofny is shown, an if you move your mouse over it, you will see the version of PHP; plus also a link to "View phpinfo()". You can click on it to view the full PHP information, including where the PHP file is located.
The PHP config file used (shown on the phpinfo() page) is shown by:
Loaded Configuration File
Hope that helps!

Two php version on mac, can i fix it?

I have a configuration problem about my php installation on my mac os x 10.9.2
If i do
php --version
on my terminal i get following output:
PHP 5.3.27 (cli) (built: Dec 4 2013 06:25:36)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
while if i try to check php version via phpinfo(), i get following
PHP Version 5.4.24
so i have two php different version installed, 5.3.27 for cli mode e 5.4.24 on server side.
Also if i try to change configuration in php.ini, at path that i see on phpinfo() response (/private/etc/php.ini), after restart apache, i don't see nothing change; so i think that php.ini maybe is in another place.
How can i do to fix my php installation to have only one php version?
If you want it 5.4 on the CLI also, try moving the one at /opt/local/bin/php out of $PATH.
Normally php lives at /usr/bin/php, so it should find that one when you move the one at /opt/local/bin/php out of $PATH. Maybe echo $PATH shows /opt/local/bin/ before /usr/bin/ for you?

Categories