Differing PHP versions using ssh - php

I am trying to setup deployer php on a shared server. And having trouble running php remotely on the server.
The server is running php 7.0.6 for normal http requests. And if I SSH in via terminal and run php -v on the remote server I get:
# php -v
PHP 7.0.6 (cli) (built: May 2 2016 02:11:49) ( NTS )
this seems good to go but if I run a remote command from my local machine:
$ ssh 'user#domain.com' 'php -v'
PHP 5.3.28 (cli) (built: Mar 29 2014 12:18:37)
obviously the remote command is not using the right php version. I found the version is set in the .bash_porfile:
export PATH=/usr/local/lib/crucial-php/php-7.0.600/bin:$PATH
but I don't know how to get the ssh remote command to respect the .bash_profile. Is there anyway to get the remote command to use the modified PATH without forcing it with source ~/.bash_profile

This turned out to be pretty simple, after reading this post:
Why does an SSH remote command get fewer environment variables then when run manually?
I copied the PATH var into my ~/.bashrc file and it worked like a charm.

Related

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.

PHP version on MacOS X 10.11 issue

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

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.

yii2: Unable to determine the entry script file path - change PHP server environment from cgi to cli

I'm using yii2 basic template for my application. I created a console command which executed successfully on my local. But when I run it in terminal on my bluehost site, I got this error "Exception 'yii\base\InvalidConfigException' with message 'Unable to determine the entry script file path.'"
I learn that the issue was about the php environment, that uses cgi instead of cli, got the info here https://github.com/yiisoft/yii2/issues/6244
I confirm it when checking the php -v
host: PHP 5.4.34 (cgi-fcgi) (built: Oct 21 2014 17:19:35)
local(dev): PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
How I can change this server environment to use cli instead of cgi.
A step by step guide with bluehost environment would be appreciated.
You're trying to run console command with PHP CGI, which have different environment.
You should use PHP CLI, so call php-cli instead of php.
Solve my same problem with
/usr/local/bin/php /home/xyz/yii hello
This problem is in Shared Hosting providers.
PHP is configured and installed on the server with two separate executable / binary files for CLI and CGI (FastCGI).
PHP CGI (FastCGI) /usr/bin/php
PHP CLI /usr/local/bin/php
Read More
phpshell or other tools that emulate like this, execute commands in CGI/FastCGI mode.
Cron Jobs in Shared Hosting are executed under cli mode

php fails parsing on one machine but not the other

I would ask in Chat, but I don't have enough points yet.
I am trying to migrate a server from a deployed setting to a virtual machine running in virtualbox. All networking works fine in the virtual machine. I have no problem posting the code, but I think it is too large and too many files.
I am completely lost. I have
Installed Ubuntu Server (updated etc)
Installed php, apache, mysql, phpmyadmin, etc
ssh'd into the current server
copied the files using tar -zcvf ./html_files_copy.tar.gz ./html/*
copied mysql stuff using mysqldump -uroot -p --all-databases > db_copy.sql
deployed both the html / php files and the mysql database
No matter what I do though, the server generates a blank page. I have looked into this as much as I can figure out and it seems that php is failing on parsing the php code.
How can I fix this and have the php not fail, and why would it work on one machine and not the other? I can copy the stuff back to the old server and it WORKS!? Mysql tables look EXACTLY the same too.
Does it make sense that the completely blank page (debug info is turned on, not sure why it doesn't say anything) is a parsing error caused by the newer PHP not knowing one version older functions anymore?
Is there a list somewhere I can use to search the code for suspect functions?
To get the following info I used phpinfo() in a php file, lsb_release -a and uname -a from terminal using ssh
- New Server
PHP Version 5.5.9-1ubuntu4.5 with Apache/2.4.7
Ubuntu 14.04.01
mysql Client API version 5.5.40
Linux ubuntu 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
- Old Server
PHP Version
5.5.9-1ubuntu4.4, with Apache/2.4.7
on Ubuntu 14.04
mysql Client API version 5.5.40
Linux linuxdesk 3.13.0-34-generic #60-Ubuntu SMP Wed Aug 13 15:45:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Check the PHP log-file or enable error display using the display_errors flag. Also enable logging of all errors: error_reporting(E_ALL); and verify these settings with phpinfo().

Categories