[Reiwa Latest Edition] Impact of PHP Versions and How to Check Them

table of contents
Introduction
Hello, this is Enoki from the System Development Department. This time, I'll be writing an article about checking your PHP version
By the way, if the PHP version is old, it may cause problems or impact security
(Actually) this article doesn't touch on that in particular, so
if you're not familiar with web systems but are curious about the impact of different PHP versions, we
recommend the article below
[Explanation] Impact of different PHP versions and countermeasures
For now, this is it
php -v
If the version information appears like this, then it's OK
PHP 8.2.1 (cli) (built: Jan 11 2023 07:28:38) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans
I can almost hear someone saying, "I know these commands, but I can't find the version, so I'm looking it up!"
If this happens (version information does not appear), the execution location may be incorrect
'php' is not recognized as an internal or external command, operable program or batch file
Where to run
This is about where to run a typical environment and what to do if it still doesn't appear
Environment Linux/Windows
First of all, the environment
Linux: Start a terminal and run
php -v Windows: Start a command prompt (or PowerShell) and run php -v
Execution location (for those wondering what an arbitrary directory is)
By any directory, I mean the directory where PHP is installed
If you think about it, it makes sense, but it cannot be executed in a place where PHP does not exist
You can find the location of your PHP installation by running the following command:
Linux:
# Command to find the PHP installation location find / -type f -name "php" -executable -print
Windows:
# Command in terminal to find PHP installation location dir /s /b php.exe
# PowerShell command to find the PHP installation location: where.exe php
This command will print the path to your PHP installation location
Once you know the location of PHP
you run the above command and it displays a path like /usr/local/bin/php
Navigate to the execution location using the path without the trailing /php
# Example of command to move to PHP installation location cd /usr/local/bin
After that, php -v , the PHP version information should be displayed correctly.
Now you can run PHP commands, but
to be honest, it's a hassle to go all the way here every time.
So, let's continue a little further.
Can be executed from anywhere through a path
Once you have found the location of PHP (installation directory), you can add it to your path
, which will allow you to use the PHP executable in any directory.
Linux
Add the path by running the following command in Terminal:
export PATH=$PATH:[installation path]
For example, if the installation path of PHP is /usr/local/bin , it will look like this:
This installation path is the path to the directory (location) where PHP is installed that you found earlier.
export PATH=$PATH:/usr/local/bin
For Windows
On Windows, you can change the environment variable settings to allow the path
1. Search for and open "Edit the System Environment Variables".
2. Click the "Environment Variables" button.
3. Select the "Path" environment variable in the "System Variables" section and click "Edit".
4. Click the "New" button and add your PHP installation path.
5. Save your changes and close the dialog.
This will add the PHP installation path to the Path environment variable, making the path valid
Now you can execute PHP commands without having to move around every time!
Use it to make your PHP life easier!
10