3 Easy Ways to Check Your PHP Version

PHP PHP
主にPHPに関する記事

Why is it Important to Check Your PHP Version?

Checking your PHP version is crucial for the following reasons:

  • Security Measures: Older PHP versions may contain vulnerabilities that put your server at risk.
  • Compatibility Check: Some functions may be deprecated in newer versions, so verifying compatibility is essential.
  • Performance Optimization: Newer versions often include improvements in speed and memory usage, making updates beneficial.

Here, we introduce three simple ways to check your PHP version.


1. Using the phpversion() Function

One of the simplest ways to check your PHP version is by using the phpversion() function.

Method

  1. Create a new PHP file (e.g., version.php) and write the following code:
<?php
echo 'Current PHP version: ' . phpversion();
?>
  1. Access version.php in your browser, and your current PHP version will be displayed.

Caution

  • Be sure to delete this file after checking, as leaving it accessible could expose sensitive information to attackers.

2. Using the phpinfo() Function

For detailed PHP information, the phpinfo() function is helpful.

Method

  1. Create a new PHP file (e.g., phpinfo.php) and write the following code:
<?php
phpinfo();
?>
  1. Access phpinfo.php in your browser, and a page displaying PHP version and settings will appear.

Caution

  • Since phpinfo.php contains server configurations and other sensitive data, delete it immediately after use.
  • If you only need the version number, use phpversion() instead for security reasons.

3. Checking via Command Line

You can also check your PHP version using the command line.

Method (by OS)

Windows

  1. Open Command Prompt
    • Press “Win + R,” type “cmd,” and press Enter.
  2. Run the following command: php --version

macOS / Linux

  1. Open Terminal
    • macOS: Press “Command + Space,” type “Terminal,” and open it.
    • Linux: Press “Ctrl + Alt + T” to open the terminal.
  2. Run the following command: php -v

Example output:

PHP 8.1.2 (cli) (built: Jan 12 2023 12:00:00)
Copyright (c) The PHP Group

4. Checking via Hosting Control Panel

If you are using a shared hosting service, you may check your PHP version from the hosting control panel.

Steps for Major Hosting Providers

Xserver

  1. Log into the server panel.
  2. Select “PHP Ver. Switch.”
  3. Your current PHP version will be displayed.

Sakura Internet

  1. Log into the control panel.
  2. Navigate to “Server Settings” → “PHP Version Settings.”
  3. Your current version will be shown.

Control panel interfaces vary by hosting provider, so refer to their official documentation for details.


Summary

MethodAdvantagesCautions
phpversion()Simple and quickDelete the file after use
phpinfo()Provides detailed infoSecurity risks, must delete after use
Command LineWorks on server environmentsRequires knowledge of terminal usage
Hosting Control PanelEasy for shared hosting usersSteps vary by provider

Regularly checking your PHP version and updating to the latest stable release helps enhance security and optimize performance.

コメント

Copied title and URL