My phpinfo.php on apache shows
PHP Version 5.4.15
but commandline
php - v
shows
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
I think apache and commandline reaches the different php,however
which php
shows only
/usr/bin/php
it is 5.4.17
I would like to know where php apache uses, and how can I check which php apache uses?
I think this depend on if you run php files using mod_php5 or cgi. The difference is explained in the accepted answer in this question: What is mod_php?
As I understand it, basically mod_php5 is pre-compiled from a specific PHP version that Apache will than use. While if CGI is used to run PHP the installed PHP command line version will be used when spawning a new process each time a PHP file is executed.
Hope this helps.
Related
I'm a begginer in Laravel and I installed XAMPP as local server. I noticed that my XAMPP already install php 7.4 as it's dependency. But when I tried php -v in www dir in php it shown.
'php' is not recognized as an internal or external command, operable
program or batch file.
But in php directory is shown
PHP 7.4.15 (cli) (built: Feb 2 2021 20:47:45) ( ZTS Visual C++ 2017
x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c)
Zend Technologies
So, should I install additional php in my system for development? Should the version of the php matche with XAMPP php 7.4?
php -v will only tell you if you have PHP installed as a command line interface (PHP-CLI) which would enable you to run php code in cmd.exe or powershell. You'd normally not need this, but for reference here's how to enable it: https://stackoverflow.com/a/10753133 (mind the comment on Windows 10).
To check if PHP runs in your webserver environment (which is by default available in xampp), create a file test.php in your www folder with the following content:
<?php
phpinfo();
?>
Call this file in a browser, you will get an overview of all php features available. Delete the file before you go productive, because it will also give hackers a lot of information (which you don't want).
Try to add XAMPP PHP to Environment Variables
here is an instructions for Windows 10
I use hosting and in my setting php version is 7.4.16. but if i use phpshell and check version with php -v output is:
PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
why?
I can not use phpshell?
Many providers have diffrent versions of php installed, try php72, php73 or ask your provider what the settings are. You may have to provide the full path to the php executable like:
/usr/bin/php-7.4/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.
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
I have upgraded to PHP 5.3 on a development machine (Windows 7 box).
php-v shows
PHP 5.3.3 (cli) (built: Jul 21 2010 20:36:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
However, phpinfo.php shows that the version on the machine is: 5.2.14 as shown
The loaded configuration file rightly loads the correct php.ini file for 5.3
The configuration file (php.ini) Path wrongly reads: C:\Windows - I don't install PHP on the said path. I have however done a recursive search of PHP folders and files within that file but the search turned up nothing.
Applications seem to use the settings reported by the phpinfo and not by php -v or php -m or php -i (or else).
Apart from deleting the PHP folder and starting from scratch (which I have done), and ensuring that Apache points to the right PHP dir using PHPINIDir, what could I possibly do to solve this? Thanks.
Hello
You should also update apache php
module
#soju - that fixed it, thanks, but I thought I'd make this a little clearer for others.
Apache requires the php module to serve php files. On Windows it comes as a .dll file. This would be called: php5apache2_2.dll - located within your php folder. Strangely though, during upgrading the php folder with a newer version, you may find out that apache still uses the old php module file. So while php -v correctly reports the new version, Apache still looks at the old php module (reported by phpinfo). To find out what module version you have, you could: right-click on the .dll file > select properties -> view the details tab. Or just hover on the file.
If this version is not what you want, you might want to hunt for a newer version and replace it. Good idea to back up first. Also, the php5apache.dll file works with and requires the file: php5ts.dll - so ensure these files are the same versions.
With your httpd.conf file with the directive:
LoadModule php5_module "\path to\php5apache2_2.dll"
You may restart apache and smile!
Your command line (CLI) php is an other version than the one used for Apache. Check also that both use the same php.ini. When you call on your Windows machine
c:\path\to\php\php.exe -v
or
c:\path\to\php\php-win.exe -v
and
c:\path\to\php\php-cli.exe -v
They all can return different versions. Often this happens when upgrading to a new WAMP version and forgetting to delete the old versions. I'm sure you will find the executable PHP binary which matches the same version. It is also save to use the php.exe or php-win.exe instead the php-cli.exe on Windows.