PHP version on MacOS X 10.11 issue - php

Recently I updated the default PHP version on MacOS X 10.11 to the newer 7.1.4, but when I do php -v on the terminal it says this: PHP 5.5.38 (cli) (built: Aug 21 2016 21:48:49).
I created the phpinfo on the web root and it says that the version is actually the 7.1.4.
What should I do to resolve this issue? Is this a real issue?

Since you said:
I used the command curl -s php-osx.liip.ch/install.sh | bash -s 7.1
I took a look at https://php-osx.liip.ch, which says:
Why does php -v on the command line still show my old version?
php-osx doesn't overwrite the php binaries installed by Apple, but
installs everything in /usr/local/php5. The new php binary is
therefore in /usr/local/php5/bin/php.
You can also adjust your PATH do include that directory, eg. write
into your ~/.profile file the following
export PATH=/usr/local/php5/bin:$PATH

Related

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)

Why phpinfo() shows a different version than php -v?

I install php via brew. With brew install PHP. My version of php-cli is 7.2
But, if I use phpinfo() on my server, I get php version 7.1.
If I use php -v in my terminal, I get php version 7.2.
Disclaimer: I'm adding this hopefully extensive answer as part of the Revival badge. (Answer more than 30 days after a question was asked as first answer scoring 2 or more)
TL;DR
php -v settings can be different from phpinfo() inside your web-server due to the running service state of fpm and your webserver. Perhaps you need to restart php-fpm and/or your web-server (apache, nginx, ..).
Long version: Command line
Command-line based calls like php -v or php -i or php test.php will read your configuration, options and arguments every time you execute your script within a terminal.
This means if you update php in your operating system then you'll get the most recent version in your terminal session.
Attention: Depending on your PATH variables you still might get an older version.
What does this mean? Even if you update your php version on your operating system you might still have an older terminal session which links to an older php-binary.
Here is an example: I am an OSX user and installed php through brew. Currently php links to php#7.3. Here is my way to validate which versions are running where. For this I'm using which php.
$ which php
/usr/local/opt/php#7.3/bin/php
$ php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
// or the equivalent "absolute path" example
$ /usr/local/opt/php#7.3/bin/php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:42) ( NTS )
I have multiple php-versions installed on my local system. I can run them all individually. Here is an example:
$ /usr/local/opt/php#7.2/bin/php -v
PHP 7.2.20 (cli) (built: Jul 5 2019 12:56:54) ( NTS )
Long version: Why is my phpinfo() using the wrong php version?
Since we now have an understanding that we can run multiple and different versions of php on a single operating system, lets dig into our web-server based script which runs phpinfo().
After installing a new php-version you'll have your binaries replaced by new versions. Awesome! but.. how does my running web server get notified about it?
For this I'll refer to the php documentation Apache 2.x on Unix systems Point 7. Also apache allows us to load different modules for PHP.
Edit your httpd.conf to load the PHP module. [...]
For PHP 7:
LoadModule php7_module modules/libphp7.so
For PHP 5:
LoadModule php5_module modules/libphp5.so
Since you are upgrading from PHP 7.1 to PHP 7.2 there is probably no change but your webserver is still running the old linked version of php.
In this case a restart of your apache webserver should help so it can pickup the new binaries correctly.
Please let me know if this will help you to solve your issue. For all the other readers: If you think there is something missing OR there is something wrong in my explanation then please let me know with a comment.

Mac OSX Terminal Setting PHP path not permanent

I've got a MAC OSX (Capitan to be precise).
I have installed PHP7 by using this line of code in the terminal:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
After it installed I run this:
export PATH=/usr/local/php5/bin:$PATH
After this when I run:
PHP -v
I get PHP 7.0.10 (cli) (built: Aug 31 2016 10:25:51) ( NTS )...
when is what I need it to do, so great BUT my problem is that as soon as I close my terminal and I run PHP -v again I get PHP 5.5
Why doesn't it keep PHP 7.0 ?
Add export PATH=/usr/local/php5/bin:$PATH to your ~/.profile dotfile so that the PATH variable is exported when you start your system (requires restart).
Or add it to ~/.bashrc file so that it gets exported when you start you start bash.
I recommend using ~/.profile.

php two diffenrent versions on mac os X

I have Mac OS 10.11.6 (15G31), Version Apache/2.4.18
in terminal
php -v
shows that
PHP 5.5.38 (cli) (built: Jul 22 2016 17:18:01)
phpinfo()
shows
PHP Version 5.5.36
two different versions, how it could be and how to delete one version?
type which php in your command line to see where your php files (of each version) are located.
If it shows exactly one php directory that's because the other one is not set in your PATH environment variable. It could be found by searching inside httpd.conf

Update path to PHP on OS X El Capitan after updating PHP 5.5.x to 5.6.x

I've updated PHP from 5.5.34 which was installed on my Mac to PHP 5.6.25 using this guide: https://coolestguidesontheplanet.com/upgrade-php-on-osx
When I upload a phpinfo() script it's showing that I'm using PHP Version 5.6.25 which is what I'm expecting.
However, in Terminal it's seeing the old version of PHP:
$ php -v
PHP 5.5.34 (cli) (built: Apr 22 2016 19:16:58)
How can I get the Terminal to use the updated version of PHP?
As usual nobody answered, but I figured it out so posting the solution...
If you follow that guide you will need to do the following:
sudo apachectl restart
That should get the correct PHP version (7.x if you follow the link right the way through to the end) working in your browser. But your Terminal will still display 5.x
In your home directory create a .bash_profile file:
cd ~
nano .bash_profile
and put this in it:
export PATH=/usr/local/php5/bin:$PATH
Save the file and exit.
Load the .bash_profile:
source .bash_profile
Now when you do php -v you should see it reporting 7.x. So it's using that in your Terminal and browser; all good.
The installer works in a strange way whereby even though you're using PHP 7.x it will put it in a directory called 'php5' (/usr/local/php5) but this is a symbolic link to a different directory.

Categories