PHP 7.0 installed, but version doesn't change - php

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

Related

How to change PHP version in XAMPP?

I've downloaded XAMPP ver. 7.2.10 which supposedly has the PHP ver. 7.2.10.
But when I run a composer update on cmd, it says that my PHP version is 7.0.21. I need to have a PHP 7.1.3 in order to run my frameworks.
Is there a way to change the PHP version without installing a new XAMPP? Because I already have the latest version installed and the PHP versions stated in the XAMPP and CMD are different.
Change you Xampserver you can't change php version inside xampserver
you can download from below link
Download xampserver
You can also do it in another way.
Download your desired version of php here and then go to XAMPP folder (most likely C:\xampp).
There, extract the downloaded php file and name it php (paste it in C:\xampp) Then, copy all files from your old php folder and paste it in the new php folder.
Do not replace any files, just copy missing files and if your php version is less than 7, don't forget to edit your httpd-xampp.conf file.
Restart your Apache server and, hopefully, it will work.
Maybe you are using another version of php, check if you have another version installed and see environment variables and path there should tell you the php path used, or maybe you have an apache running, to stop it enter services and stop apache24.
Your Bash/Terminal runs in it's own PHP world.
You can upgrade it with apt-get on XAMPP VM
see here:
https://die-schwarzwald-werbeagentur.zazudesign.de/internet-programmierung/a-working-typo3-9-4-x-composer-installation-on-xampp-osx-php7-2-imagemagick-mariadb.html
After upgrading PHP to 7.2 composer will work. For some reason composer uses the bash PHP-version and not the Apache2-PHP-Version

CentOS ./configure -- how to use alternate PHP version

I am quite new to CentOS.
On my CentOS web server I have PHP 5.4.16 as a native PHP version though I also have alternate PHP version 7.0.
I am trying to install xDebug for PHP 7.0 following the instruction on https://xdebug.org and one of the steps is to run
./configure
When I run ./configure command I am getting error message:
not supported. Need a PHP version >= 5.5.0 and < 7.2.0 (found 5.4.16)
So my question is how do I tell ./configure to use alternate PHP version 7.0?
If you run php -v on command line, it will output the version of PHP it is currently on your PATH. My guess is that it will return the older version of PHP as the result.
The quick and dirty way to try and get it to use version 7.0 for your current shell session would be to run the following
set PATH="/your/path/to/php7/bin:$PATH"
php -v
//Should output version 7.0
You could also try checking in /usr/bin or /usr/local/bin to see exactly which PHP binary it's pointing to, and manually change the location that the symlinks are pointing to.
Another option would be to try creating an alias in your ~/.bashrc file for PHP by editing the file and adding the following to the end:
alias php="/your/path/to/php/7/bin/php"
Then restart your shell session (i.e. close an & re-open PuTTY or whichever SSH client you're using).
Now type php -v and you should see it change to version 7.0.

I'm getting php5.5 instead php7 when I run exec(php -v) in php script

When I run php -v in cli I get the exact php version 7, but when i run exec("php -v") in web server I get php 5.5 even thought in phpinfo i see that I am runing php 7?! Any idea why I get the older version of PHP?
running exec you get the CLI version of PHP
you probably installed php5.5 as CLI and php7 as apache module
If you use CentOs, add this line at the end of /etc/bashrc (or ~/.profile for Ubuntu)
export PATH=$PATH:/your/path/to/php7/bin
Then run:
source /etc/bashrc
P/s It may be better if you edit /etc/profile.d. Take a look both of them.
UPDATE
In MacOS, let edit ~/.bash_profile (create it if it does not exist) with the same content.

Composer use MAMP PHP Version

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)

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.

Categories