Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Check PHP Version (Apache/Nginx/CLI)

    How to Check PHP Version (Apache/Nginx/CLI)

    By RahulJanuary 13, 20233 Mins Read

    PHP (Hypertext Preprocessor) is a popular programming language generally used for web development. It was originally developed by the Danish-Canadian programmer Rasmus Lerdorf in the year 1994. It can be used either via the command line or used with popular web servers like Apache or Nginx. Apache has a PHP module to directly run PHP files but Nginx required a PHP-FPM package to work with PHP files.

    Advertisement

    This tutorial will help you to check the PHP version installed on your system. Also, what is the active version of PHP on the command line as well as the check PHP version used by Apache or Nginx? As we can install multiple PHP versions on a single system, it can be the there are different version’s active on CLI and Web servers.

    Check PHP Version (CLI)

    By default, there can be one default PHP version that can use with standard binary. To check the PHP version currently active on the command line, execute the following command on the terminal:

    php -v 
    
    Output
    PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:28) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

    On Ubuntu and Debian systems, you can also access another version by pointing their versions like: php7.2 or php7.3 etc.

    • Install PHP on Ubuntu 20.04
    • Install PHP on CentOS 8
    • Install PHP on Debian 10

    Check PHP Version (Apache/Nginx)

    This is fine that, the current active PHP version on the command line is different than the version used by the Apache or Nginx web servers. It’s also possible that two virtual hosts can use different-2 PHP versions by using PHP-FPM.

    So, to check the currently active version for Apache or Nginx, navigate to the document root of the website to which you want to check the PHP version. For example, my document root is “/var/www/html”:

    cd /var/www/html 
    

    Then create and edit a PHP script file in your favorite text editor:

    nano phpinfo.php 
    

    And, add the following content to the files. Here we used built-in phpinfo() function, which prints the active PHP version details:

    1
    2
    3
    <?php
      phpinfo();
    ?>

    Press “CTRL +X” and hit Enter button. Then press ‘Y’ and again hit Enter to save and exit from text editor.

    Next, open a web browser and access `https://localhost/phpinfo.php` URL. Update localhost with the IP address or the configured domain name on the system checking php version.

    https://localhost/phpinfo.php

    How to Check PHP Version
    phpinfo() Function Result

    The output will show you all the details related to active PHP along with the PHP version. It will show you the values of the PHP variables, a list of enabled PHP modules along with their version and other details.

    PHP version
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.