If you're interested in implementing new features on your website, or are trying to pinpoint a bug, you may need to check the version of PHP that your server is currently running. You can check the version by running a simple PHP file on your webs server. You can also check what version is installed on your local computer using the Command Prompt or Terminal.

Method 1
Method 1 of 2:

Web Server

  1. 1
    Open a text or code editor. You can use Notepad or TextEdit. Don't use a word processor such as Microsoft Word.
  2. 2
    Enter the following code. This small piece of code will return the PHP version information when it is run on your web server.[1]
    <?php
    echo 'Current PHP version: ' . phpversion();
    ?>
    
    Advertisement
  3. 3
    Save the file as a PHP file. Click "File" → "Save as" and then give the file a name. Add the .php extension to the end of the file name. Name it something simple, like version.php.
  4. 4
    Create a more detailed report (optional). The file above will output your current PHP version number, but if you want more information, such as system info, build dates, available commands, API information, and more, you can use the phpinfo() command. Save the file as info.php.
    <?php
    phpinfo();
    ?>
    
  5. 5
    Upload the file(s) to your web server. You may have to use an FTP client, or you may be able to upload through your server's admin control panel. Place the file(s) in the root directory of your web server.
  6. 6
    Open the file in your web browser. Once the file has been uploaded to the server, you can use your browser to load the file. Navigate to the location of the file on your server. For example, if you placed it in the root directory of your domain, you would visit www.yourdomain.com/version.php.
    • To see the full readout, visit www.yourdomain.com/info.php.
  7. Advertisement
Method 2
Method 2 of 2:

Local PHP Version

  1. 1
    Open the Command Prompt or Terminal. If you have PHP installed locally, you can use the Command Prompt or Terminal to check the version. This also works if you use SSH to create a remote connection to your server via the command line.
    • Windows - Press Win+R and type cmd.
    • Mac - Open Terminal from the Utilities folder.
    • Linux - Open Terminal from the dash, or by pressing Ctrl+Alt+T.
  2. 2
    Enter the command to check the PHP version. When you run the command, the installed version of PHP will be displayed.
    • Windows, Mac, Linux - php -v
  3. 3
    Fix the version not appearing in Windows. A common problem for Windows users is PHP not being included in the system path, resulting in the message ‘php.exe’ is not recognized as an internal or external command, operable program or batch file.[2]
    • Find the location of your php.exe file. This is usually C:\php\php.exe, but you may have changed this during installation.
    • Type set PATH=%PATH%;C:\php\php.exe and press Enter. Change the actual location if yours is different.
    • Run php -v again. You should now be able to see the version number.
  4. Advertisement

Community Q&A

  • Question
    When I use the PHP -v command it says 'PHP' is not recognized as an internal or external command, operable program or batch file. Why?
    Arrogance
    Arrogance
    Top Answerer
    This is caused by PHP not being in your PATH. Follow the directions under Method 2 for setting your PATH variable.
  • Question
    `phpinfo` and `php -v` show different versions of PHP. How do you resolve this and change php -v to the desired version?
    Arrogance
    Arrogance
    Top Answerer
    `phpinfo` returns the version being used by your web server. `php -v` is the version installed in your PATH (where the operating system looks for programs to run from the command line). Check your web server setup, to find the path of the PHP interpreter it is using. Then, either invoke it by entering the full path (like C:\Programs Files\php.exe or /usr/bin/php), or add its parent directory to the top of your path variable (as described in the article. In Linux, the php command may be symlinked to a specific version, while the web server invokes another version. You'll need to modify the symlink, or run the command for your distro to select an alternative.
Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 14 people, some anonymous, worked to edit and improve it over time. This article has been viewed 917,562 times.
How helpful is this?
Co-authors: 14
Updated: October 8, 2020
Views: 917,562
Categories: Web Programming
Article SummaryX

To find the version of PHP running on your web server, create and upload a script called "version.php" that contains some brief code, then access that script in your web browser.

Did this summary help you?
Advertisement