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

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.

Related

Install and configure PHP5 and 7 on same Ubuntu server

I have installed both PHP versions (php5 & php7) on the same Linux server and it works for me, when I switch the version configuration on system.
Also it shows changes happen in the info.php file in the browser, but in terminal using php -v ,it shows only php7 version installed though it works under php5.
how can i correct the version information in php5 while chk in terminal?
When PHP is installed side to side there are different executables for the different versions. When you use a Web Server you choose which version to use via its configuration.
If php -v shows PHP 7 try php5 -v. If this returns the right version you can use php5 to run any script with php5.
To find out where exactly the PHP executables are use:
which php
whereis php
which php7
whereis php7

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.

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

Vagrant uses old php version

Can't find this online, probably not describing it properly because I'm pretty sure I am not alone with this problem.
I have vagrant running for a few months now, with PHP 5.6. Now I upgraded to PHP 7, but when I request my php -v inside Homestead in Terminal it still gives me version 5.6.
When I request my PHP version with this snippet <?php phpinfo() ?> inside a webpage I DO get version 7.
Is this normal or am I forgetting something?
Thanks
UPDATE
I have version 7.0 in my vagrant ssh right now. But apperently there is a different environment for ssh, ftp, code, ...
How do I set all of these versions to the same (obviously the latest 7.0 version)
Try this and if it's the right path of php7 you can use php7.0 instead of php
/usr/bin/php7.0 -v

Ubuntu Command Line Reports PHP version as 5.3.3 but phpinfo says 5.5.9

When I look at a phpinfo page on my ubuntu server it says the php version is 5.5.9. But when I do a php -i or -v from command line it says php version 5.3.3 and it doesn't list the modules I've installed in 5.5.9.
I guess I have two versions running. How do I get rid of 5.3.3 so command line reports 5.5.9?
Do a locate bin/php to see all files on your system that might possibly be PHP binaries. Then do a which php to see which one would be executed. I have one in /usr/bin/php and a self-compiled version in /usr/local/bin/php53, of varying versions.
To run things on the command line with the other version, you can specify the full path of PHP thus: /usr/local/bin/php /command/to/run and it will run that. Or, add the path to the new version to your system path at the start, and this will "see" the new PHP version before the old one.
If you are running this thing from cron, I tend to recommend using the full path to the PHP interpreter anyway - I think it's a good habit, in case the available paths are different between your environment and the cron environment.

Categories