Phpinfo path to php

How To Check PHP Version And PHP Install Path On Linux And Windows

After you install PHP or LAMP on a Linux server ( or XAMP on a Windows Server ), if you want to run command php in a terminal to execute a .php script file, you should first find the PHP install path and add the php executable file path in system environment variable PATH‘s value.

But if there are multiple PHP version installed on the server, you should find the PHP version and related PHP install path which you need, and then you can run it accordingly. For example, you can invoke your required PHP version executable file on the Linux Cron job.

This article will tell you how to check current PHP version and PHP install path in both Linux and Windows. It will also tell you how to change current PHP version to another one by edit the system environment variable PATH‘s value.

1. Check PHP Install Path On Linux.

The whereis command returns the executable file path. From below example, we can see the PHP executable file path is /usr/bin/php , and it is linked to /www/server/php/73/bin/php file ( this is the real PHP executable file ).

$ whereis php php: /usr/bin/php $ $ ls -l /usr/bin/php lrwxrwxrwx. 1 root root 26 Dec 21 09:08 /usr/bin/php -> /www/server/php/73/bin/php

If whereis command returns multiple PHP install path, then you can run which command to get current PHP executable file path.

$ whereis php php: /usr/bin/php /usr/local/bin/php /usr/local/lib/php.ini $ $ which php /usr/local/bin/php

2. Check PHP Install Path On Windows.

It is very easy for you to check PHP install path on Windows, because install PHP on Windows is just download the PHP zip file and unzip it to a local folder, then you can run it in a dos window like below. In below example, the php install path is C:\xampp\php\.

C:\WorkSpace>C:\xampp\php\php -v PHP 8.0.0 (cli) (built: Nov 24 2020 22:02:57) ( ZTS Visual C++ 2019 x64 ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

If you want to run above example just by input command php -v, then you need to add the PHP install path ( C:\xampp\php\ ) in Windows system environment variable PATH‘s value. You can read article How To Set Windows Environment Variables.

# First make sure php install path has been added in windows environment variable PATH's value. C:\WorkSpace>echo %PATH% . ;C:\xampp\php # Now you can run command php in command console. C:\WorkSpace>php -v PHP 8.0.0 (cli) (built: Nov 24 2020 22:02:57) ( ZTS Visual C++ 2019 x64 ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

3. Check Current PHP Version.

Run php -v command in a terminal to get the current executed PHP version.

# php -v PHP 7.9.9. (cli) (built: Dec 21 2020 09:06:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies

3. Use phpinfo() Function To Get PHP Version & PHP Install Path.

  1. The phpinfo() function can return a lot of useful information ( includes PHP Version and Install Path ) about currently used PHP.
  2. We can write a .php script file and contain the phpinfo() function in this file. Then we can execute it both in command-line or from HTTP web server.
  3. Open a terminal, run command vi test.php to create a .php script file.
  4. Press esc , i key to enter insert mode.
  5. Copy below source code into the test.php file.
$ php ./test.php phpinfo() PHP Version => 7.3.11 . .

Источник

phpinfo() and php -v shows different version of PHP

Now I am confused which version of PHP I am using. The files are uploaded to the hosting website and I cannot make any changes to the config files like httpd.conf or php.ini .

7 Answers 7

Shorter answer.

Don’t panic! If you are concerned about what PHP version your Apache server is using, the output of phpinfo() is always what you should pay attention to. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.

In fact you can compile and load various PHP versions you want to work with Apache as long as you adjust Apache to properly load it. The PHP command line interface will never come into play in the case of Apache parsing PHP pages.

The command line version of PHP is simply there for command line specific tasks and the PHP module for Apache will never touch, use or need that.

Longer answer.

I wanted to know which php version I am using so I wrote the standard script:

Which gives me PHP version 5.6.10- the correct PHP version needed for my application. When I tried in terminal:

It shows me PHP version 5.3.2 which I don’t need.

The version of PHP available from the command line has 100% nothing to do with the version of PHP loaded as a module. These are completely separate things.

So if you are concerned about which version of PHP your web application is using, if phpinfo() shows version 5.6.10 and that is what you want/need that is 100% fine.

The command line version of PHP is a completely separate system item. So the only thing that matters is the output of phpinfo() .

If for some reason you wanted to use a different version of PHP with Apache, all you need to do is install the compiled Apache PHP module somewhere and add—or adjust—this line in your system’s Apache config:

LoadModule php5_module /path/to/php/and/the/module/for/apache2/libphp5.so 

And just adjust the path to the libphp5.so —which is what Apache uses to parse PHP—then restart Apache and you are in business.

For example, at one point I had to compile PHP version 5.1.6 from source (with GD library support) for use on an Ubuntu 12.04 machine running PHP 5.3.5. In the server’s PHP module loading file here:

/etc/apache2/mods-available/php5.load 
# LoadModule php5_module /usr/lib/apache2/modules/libphp535.so LoadModule php5_module /usr/lib/apache2/modules/libphp516-gd.so 

Note how one line is commented out for libphp535.so and the other one for libphp516-gd.so is uncommented? What I did is I renamed the default PHP 5.3.5 libphp5.so Apache module to libphp535.so with the version number in the name so I could have it there for reference and then named the PHP 5.1.6 (with GD library support) module libphp516-gd.so so I know what that is as well. This way I have them both available to me side-by-side on the system.

And—like I said at the outset—the PHP version used in the command line has utterly nothing to do with the Apache PHP module. So you can have any number of different versions of Apache PHP modules sitting on the system ready to go; just adjust a config and restart Apache and you should be all in business to use whatever PHP version you specified Apache should use.

Источник

How can I get the path of the PHP binary from PHP?

How can I get the binary path of php from PHP? I saw it in phpinfo(), but I need another method that gets it in Linux and Windows systems.

9 Answers 9

Also, the predefined constant PHP_BINDIR gives the directory where the PHP executable is found.

It looks like, for security reasons, $_SERVER values are not exposed.

In Windows, the PHP_BINDIR constant seems to point to «C:\php5» even if php is in a totally different directory, like for me «C:\dev\php». Here, PHP is setup as an apache module.

PHP_BINDIR is set at compile time which means that it is wrong in most cases. PHP_BINARY is set at runtime. So use this instead.

Linux Only

Use the «which» command to find php .

Note this does not guarantee the same php executable that your web server may be using, but rather the first instance that was found while looking through the paths.

This does not necessarily result in the correct php binary, since Apache and the command line might very well be using different ones.

A method using environment variables, assuming the php executable is in the system path.

function getPHPExecutableFromPath() < $paths = explode(PATH_SEPARATOR, getenv('PATH')); foreach ($paths as $path) < // We need this for XAMPP (Windows) if (strstr($path, 'php.exe') && isset($_SERVER["WINDIR"]) && file_exists($path) && is_file($path)) < return $path; >else < $php_executable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : ""); if (file_exists($php_executable) && is_file($php_executable)) < return $php_executable; >> > return FALSE; // Not found > 

@ggirtsou I don’t get your edit. why would the Windows Path contain an entry with «php.exe» ? If it is something specific to XAMPP please at least add a meaningful comment in the code.

Maybe the best solution is in the Symfony process component:

Normally, in a simple default PHP installation under Windows, the php.ini file is located and loaded from the same directory of the PHP binary.

To simplify, Windows users:

echo dirname(php_ini_loaded_file()).DIRECTORY_SEPARATOR.'php.exe'; 

Of course, if you are using multiple .ini files, it may not work if the files are not into the same PHP binary directory. BTW, this may solve to most of cases. Windows developers running PHP from local development environment.

Источник

How to check where Apache is looking for a php.ini file?

I have a feeling that Apache is using a different php.ini file that the one I am editing. I make a change in my php.ini file, restart Apache, and the change doesn’t take affect. So I don’t know what to do anymore. Any ideas? Update: Found out it’s using the right php.ini file. but I still don’t know what to do!

Note: The php-cli ‘s php.ini file is different then apache2 ‘s php.ini file. I suggest symbolic linking one to another to keep them in sync and avoid confusion!

echo php_ini_loaded_file(); PHP docs, php ANYTHING in console gives stuff for CLI php which in lot of if not most cases is a different one.

5 Answers 5

To find the file that’s being run by PHP, create a phpinfo file (just ) and look for the ‘Configuration File (php.ini) Path’ directive.

from the command line, run

This will describe the location php is loading its ini file from. You can reconfigure the php.ini location by recompiling php.

this will show you ini file of php-cli which is not necessarily the same one used by apache php module

Here is a command for Ubuntu ls /etc/apache2/mods-enabled/php*.load , above comment will only work if you have only 1 version of PHP.

The output from phpinfo() will contain this. When using PHP as an Apache module, it can be configured using PHPIniDir in httpd.conf (or similar).

To get the php.ini file which is being used by Apache you will probably have to add phpinfo() into a .php file and open it in the browser. As php -r «phpinfo();» | grep php.ini will outout the same as php —ini would. Which php.ini is used for the CLI.

Question for you, what platform are you running on unix or windows? If it is unix based, check if your php.ini is residing in the same directory as /etc/httpd. Again, installation of apache can vary so check. or issue the command «find / -name php.ini -print» (without quotes) to see which one is it you are using

Ok. Since you said you have found the correct php.ini, sounds like something is missing when you edited the php.ini and reloaded apache. Look in the log directory /var/log/httpd for error_log and check to see if there was errors. that would be a start!

Hmmm. you are running Snow Leopard (I am not familiar with it but can guess it is similar to freebsd variant). it would be worth your while to dig around in /var/log and see where the log file is kept. or even better check in the httpd.conf (the configuration file for apache) to see where the actual log file is stored into.

Источник

Читайте также:  Unable to resolve table java
Оцените статью