When setting up web application or building a website, it can be handy to know what version of PHP I have. Here, below, different methods to find out.
To know my PHP version via the command line
The command line will be of great help under Linux, I can very simply know my version of PHP via the execution of a PHP command with the option "-v" as follows: php -v
To know my PHP version via Debian packages
Debian is a free operating system for a computer. An operating system is the set of basic programs and utilities that allow a computer to run. Debian is more than just an operating system: it contains more than 43,000 packages. Packages are precompiled software components designed to be easily installed on your machine.
I can find out via my command-line package (apt-get as part of Debian), as follows: apt-cache policy php5
I get the version of PHP installed but also the version present in the repositories to know if an update is to be done.
To know my version via the file Phpinfo
I can also find out via Phpinfo which is a PHP function that I can put in a file at the root of my web server for example. To know my version of PHP, I create a new script named phpinfo.php, I open it with a text editor and I write phpinfo () inside. I write it on 3 lines with the PHP opening and closing tags. I do not forget to give read and execute rights to the www-data user. Then I access this script via my browser by typing its URL.
I ask for help to a php programmer
A php developer can retrieve the version number of PHP installed on the server in a variable, for example to perform special processing for certain versions, to ensure backward compatibility, using the native phpversion () function. He can also create my website in PHP.