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.
Related
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.
I'm using Mac High Sierra. I installed PHP (with GMP) using
brew install php72-gmp
Everything installed successfully, per the messages given, but it would seem I still have an old version of PHP 7.1 somewhere on my machine because when I run
localhost:php-7.2.1 davea$ which php
/usr/bin/php
localhost:php-7.2.1 davea$ /usr/bin/php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
So I'd like to figure out where to put the homebrew version of PHP ahead in my PATH so that that version gets picked up first.
EDIT:
As of 2018 and the latest updates to Brew your php formula names have the following format php#7.2.
When you run brew info php#7.2 your path should be /usr/local/Cellar/php#7.2/
And there will be a symbolic link to /usr/local/bin/opt/php#7.2/
So in order to change your php installation you just need to run this in terminal:
echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.2/sbin:$PATH"' >> ~/.bash_profile
or put it manually in your .bash_profile like this:
export PATH="/usr/local/opt/php#7.2/bin:$PATH"
export PATH="/usr/local/opt/php#7.2/sbin:$PATH"
===========================================================================
The location of your Homebrew installed php should be /usr/local/Cellar/php72
These are the steps you need to do to setup your PHP on macOS:
After you install php with brew run this in terminal:
export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"
Then run:
source ~/.bash_profile
To check your current active version of php run this in terminal:
which php
EDIT:
run brew info php72 in console to get all info, hints and caveats for php, it is really useful, for example this comes from brew info:
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the
following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent
configuration file:
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
Check if you have two php directories in '/usr/bin/' or '/usr/local/bin/'. If yes do a link to the good directory. See this link, may be it helps you.
As you are familiar with linux, homebrew has its own /opt and /etc path
# > echo $(brew --prefix)
# /opt/homebrew
so the paths are (for Apple Silicon):
/opt/homebrew/opt
/opt/homebrew/etc
in linux, php is installed in /etc/php/7.4
in mac homebrew, php is installed in /opt/homebrew/etc/php/7.4.
Please find the homebrew document on the default installation path for Apple Silicon 1
ref 2
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.
Is it possible to install php-cgi on Mac OS X Yosemite keeping the standard PHP version provided by the OS?
Thanks,
Alberto
You can install PHP easily with Homebrew:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php54
Homebrew doesn't change the version of the system PHP. System and Homebrew versions are located in different directories. This is how it looks like for me:
System /usr/bin/php:
/usr/bin/php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Homebrew /usr/local/bin/php:
/usr/local/bin/php -v
PHP 5.6.2 (cli) (built: Nov 14 2014 10:30:28)
If you wish to use PHP CGI on Mac OS X you will need PHP build with the CGI enabled. By default, PHP version 4.3 and higher is built with "-enable-cli" option so default interface is CLI (Command Line Interface). You can check this by running "php -v" from the shell. Output will probably be something like this:
PHP 4.4.4 (cli) ....
CLI does not output any headers and output is plain text by default. More details about this is available here.
In order to use PHP with the wxWebServer (or any other CGI application), you will need to build your own PHP binaries with CGI SAPI. It's simple, it takes only 15 minutes and you will be proud of yourself for having a "personal" build of the PHP. Here is the procedure, step by step:
Download the complete source code for the latest PHP version from php.net. Instructions here are for PHP 5.2.3 but should work for PHP 4 as well. I tested with 4.4.7 too.
Unpack downloaded archive somewhere, for example ~/Temp/php-5.2.3
Open terminal window (shell) and go to folder where you unpacked files:
cd ~/Temp/php-5.2.3
Decide where you want to install this custom PHP build and create folder. This document will assume it's custom folder under your home folder, for example if user name is webdev it's /Users/webdev/custom/php5
Create that folder (in Finder or in Terminal with "mkdir ~/custom; mkdir ~/custom/php5")
Go back to that Terminal window, you should still be in ~/Temp/php-5.2.3.
Run ./configure with CLI disabled if you are planning to use this private PHP build only for CGI. Modify paths and options to reflect your preferences.
You don't need option "--disable-cli", you can replace it with "--enable-cli" if you plan to use this PHP for something more. You will get both binaries but you will need to use php-cgi in wxWebServer.
Here is a full command line for .configure that should produce PHP with all common options and CLI disabled:
./configure --prefix=/Users/webdev/custom/php5 --disable-cli --enable-cgi --enable-trans-sid
--enable-mbstring --with-xml --enable-exif --enable-mbregex --enable-dbx --enable-sockets
--with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc
--with-mysql=/usr/local/mysql --without-pear
When configure is completed, run
make install
Edit your profile (~/.profile) to add new php path before existing one. Add something like this to the end of your .profile file:
PATH=~/custom/php5/bin:$PATH
export PATH
If you don't know how to edit profile from the command line, just create a plain text file in TextEdit containing those 2 lines and save it in your home folder (~/Users/webdev) as newpath.txt. Then open Terminal and enter command:
cat newpath.txt >> .profile
The easiest way for changes to take effect is to log out and log back in (or you can use source command).
Congratulations, you now have a custom php installation! If you wish to use other PHP just comment your changes to .profile
Verify your new PHP is the default one:
# which php-cgi
/Users/webdev/custom/php5/bin/php-cgi
php-cgi -v
PHP 5.2.3 (cgi) (built: Jul 11 2007 00:48:59)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
If you wish, you may now delete the source files in ~/Temp/php-5.2.3. To remove you custom PHP just delete target folder, i.e.
"/Users/webdev/custom/php4".
Once you have custom php installation, configure wxWebServer to use new php binaries. Regardless if you enabled or disabled CLI, you can use php-cgi (output of "which php-cgi", in this case
"/Users/webdev/custom/php5/bin/php-cgi").
If you disabled CLI build, you may also use php binary as it will be CGI build. That's it, enjoy your personal PHP build!
Found It Here
I would tring to update my php version to the version 5.5+ latest
When I'm looking via /usr/local/bin/php -v in the console I see the version 5.5+ and with php -v it tell me there is the version 5.4 installed.
How can I remove the older version 5.4 and install latest 5.5+ latest?
Typically I've used the PHP package from liip.ch
From terminal, run:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
It will not remove the default installation of PHP 5.4 from your system, but it does not have any impact on using PHP 5.5. They address the issue with php -v in their FAQ.
Prerequisites
Xcode and it's Command line utilities (install form preferences) will give you a gcc compiler to build the php with libjpeg, libpng etc. if you want to build with these.
OR run this command on terminal to install Command line tools
xcode-select --install
Building and installing php:
Download the distribution from www.php.net/downloads.php
Untar the archive and point your console into the location
Now, having still the original old php installed, run php -i | head in the console. What you want is to configure your new php with these flags to ensure you have proper pcre support and everything works just fine.
In the php source directory you untarred, run the ./configure script with the flags you just got
Build php by running make and sudo make install afterwards. That will actually replace the original php distributed with OS X.
Example sample run terminal commands:
Download latest version from http://php.net and after ruin below commands
tar -zxvf php_scource.tar.gz
cd php_source/
php -i | head
./configure --prefix=/usr --with-snmp # ... same flags as previous build
make
sudo make install
end of the workflow for building php and just check latest version from terminal commands
$ php -v
sample output of php -v
PHP 5.5.10 (cli) (built: Mar 27 2014 16:50:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
OSX Mavericks runs PHP from /usr/bin/php so in order to run the new version that you want from /usr/local/bin/php, you need to copy this file over to the /usr/bin directory. If you want to save your old version of php, first go to the /usr/bin directory
cd /usr/bin
and rename your old php file
sudo mv php php.old
Then go to the /usr/bin/local directory:
cd /usr/local/bin
and then copy the php file over to /usr/bin using sudo:
sudo cp php /usr/bin
OSX Mavericks has /usr/bin first in its environment path, so the php in /usr/bin is found before it gets to the php in /usr/local/bin. Once you copy your new php file over, when you run
php -v
Which will display something like:
PHP 5.6.23 (cli) (built: Jun 24 2016 21:08:07)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
It will have your new version that was installed at /usr/local/bin/php that you copied over to /usr/bin/php instead of version 5.4. If you're running Apache and want your webserver to also use the new php version, you'll also need to update the httpd.conf file to point at the new php_module, but that's a different question.