different result between phpinfo.php and php-v - php

i was using appserv 5.8
and in my phpinfo.php the php version was 5.6.26
now i installed laravel5.5
and its required phpversion 7
so i changed the php version to 7 from 5
now in my phpinfo.php
PHP Version 7.0.11
and when i write in the command
php -v
its give me
PHP 5.6.26 (cli) (built: Sep 15 2016 18:12:07)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
and i cant install the packages with laravel 5.5 bc the version in command line is 5.6 not 7
but when i check in phpinfo its 7
i have read something thats the command php -v tack the version from php-cli
so how can i change the php -v to be 7.0.1 as phpinfo.php
thanks ..

phpinfo.php shows what version of PHP Apache is using. -v shows what's in your $PATH.
If you're on a Mac I recommend using homebrew to install php 7 as described here
To clarify, PHP can be run in 3 ways: behind a web server, for command line scripting, and for GUI building. You have 2 versions: the web server one, which Apache is calling and invoking phpinfo.php, and PHP-CLI, which is invoked from the command line with php -v.

It seems like your PHP CLI version is different than the PHP web version. Upgrade your PHP CLI package.

You have two PHP binaries installed. In my Mac OSX:
$ which php
/usr/local/bin/php
$ /usr/local/bin/php -v
PHP 7.0.20 (cli) (built: Jul 12 2017 09:47:44) ( NTS )
And in same machine:
$ whereis php
/usr/bin/php
$ /usr/bin/php -v
PHP 5.6.30 (cli) (built: Feb 7 2017 16:18:37)
You should put /usr/local/bin in your PATH. Edit ~/.bash_profile
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Open a new terminal and check your php version.

For me(Windows) changing CLI version also didn't work, finally
changing PHP version at Environment Variable PATH worked!!

Related

PHP IntelliSense on Fedora, executable not found

I have Visual Studio Code installed on Fedora V 36. Even though I've set the php executable in the setttings.json file I'm still getting
PHP executable not found. Install PHP 7.4.0 or higher and add it to your PATH or set the php.executablePath setting
settings.json
{
"php.executablePath": "/usr/bin/php",
"php.validate.executablePath": "/usr/bin/php",
}
whereis php shows
php: /usr/bin/php /usr/lib64/php /usr/share/php /usr/share/man/man1/php.1.gz
php -v shows
PHP 8.0.24 (cli) (built: Sep 28 2022 15:32:34) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.24, Copyright (c) Zend Technologies
The question is, how can I get VS Code, or rather IntelliSense, to recognize the php executable?
The answer was that VsCode was having a permission issue with the php executable, due to VsCode being installed from Flatpak.
After some trial and error I ended up uninstalling the Flatpak version of VsCode and re-installing with directions from the official site.
https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions

Centos 8 PHP 56

I am trying to install php 5.6 on centos 8. I understand it is no longer supported (eol), but due to an old project, it needs it.
I have tried:
sudo dnf --enablerepo=remi install php56
Installs with no issue, hitting localhhost/ throws an error
Running php --version gives me an error
bash: /usr/bin/php: No such file or directory
Howver running php56 --version works.
How do i make it such that any reference to php will use php56?
The Software Collections are designed for parallel installation of multiple versions. So you have to enable the collection of the version you want.
Example:
$ module load php80
$ php -v
PHP 8.0.9 (cli) (built: Jul 29 2021 12:53:58) ( NTS gcc x86_64 )
$ module load php56
$ php -v
PHP 5.6.40 (cli) (built: Jun 28 2021 00:00:00)
For web server, if only one version is installed, it will be used for all pages.
If multiple versions are installed you have to set the proper handler (socket path) for each vhost / project / directory to use the wanted FPM backend.
How do i make it such that any reference to php will use php56?
If you really need only one version, you can also install the php56-syspaths package, which provides /usr/bin/php (a symlink)

PHPUnit error - Can't run Laravel tests from Command line using MAMP Server

I've been having this issue for quite some time now. First of all, I have MAMP Pro Server installed on my Mac OS and the default PHP Version selected is 7.3.8. I have also checked the 'Make this version available on the command line' option. But whenever I try to run laravel tests using the phpunit command, I get the following error;
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
This version of PHPUnit is supported on PHP 7.2, PHP 7.3, and PHP 7.4.
You are using PHP 7.1.16 (/usr/bin/php).
I have confirmed my php version on available on the command line using php -v an it outputs
PHP 7.3.8 (cli) (built: Aug 14 2019 16:42:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
Please kindly help.
Your /usr/bin/php file does not link to your MAMPs version of php. This file is used by phpunit (in your case).
Let me tell you how you can switch it:
First of all, move away the original link
sudo mv /usr/bin/php /usr/bin/php.bak
Then link /usr/bin/php to your actual MAMP PHP version:
sudo ln -s /Applications/MAMP/bin/php/php7.3.8/bin /usr/bin/php
Validate it with /usr/bin/php -v giving you the 7.3.8 version.

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.

OS X Mavericks how to upgrade PHP 5.4 to 5.5+ latest?

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.

Categories