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

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%

# 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.
  6. Press esc, :wq! , return key to save the edited file and exit.
  7. Run php ./test.php in command line. You can get below output messages.
    $ php ./test.php
    PHP Version => 7.3.11


  1. phpinfo

Subscribe to receive more programming tricks.

We don’t spam!

Subscribe to receive more programming tricks.

We don’t spam!

4 3 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments
Arto Muhli
Arto Muhli

Hi, you with little less experienced journeyman

I actually lowered my add-blocker for your touching plea.
Man rarely find website with good quality and vision with commitment.
I salute you, but you could get more hold on those advertisers and determine where and what manner they put their adds.

To the point.. Couldn’t give you five stars, wanted though…



Thanks you so much!!!

Would love your thoughts, please comment.x