What is PHP?
PHP is a widely used open-source web scripting language. Created in 1994, it has evolved into one of the most commonly used online languages, powering approximately 80% of websites globally. This is mainly due to its flexibility, ease of use, and support from significant content management systems (CMS) like WordPress, Joomla, and Drupal, as well as numerous frameworks and custom applications.
PHP is processed by the server rather than the user’s browser. It processes code to generate HTML dynamically, enabling developers to create interactive, data-driven web applications. PHP integrates easily with databases, handles user sessions, processes forms, and supports many other functionalities necessary for modern websites.
Tools and Environments Covered
To help you check your PHP version and configuration quickly, we’ll cover several methods and tools suitable for different environments:
- Command-line interface (CLI): This is ideal for users accessing a server’s command line. We’ll cover the necessary PHP commands for version and configuration checks.
- Web-Based PHP Scripts: These scripts allow you to retrieve PHP information via a browser, which is helpful for those on shared hosting or without command-line access.
- Hosting Control Panels (cPanel, Plesk): Many hosting providers offer control panels with built-in PHP versions and configuration management tools.
- CMS-Specific Solutions: Some CMS platforms, like WordPress and Joomla, provide plugins or built-in tools for checking PHP configurations, making it easy for non-technical users to retrieve this information.
1. Why Checking PHP Version and Configuration is Important
- Compatibility: Many applications require specific PHP versions. For instance, WordPress recommends PHP 7.4 or higher, while Laravel 9 requires PHP 8.0. Using an incompatible version can cause errors or limit functionality.
- Security: PHP in older versions does not have updated security mechanisms. Your server is an excellent target. Running current versions and to the latest stable version of PHP makes you secure with the updated patches.
2. Methods to Check PHP Version and Configuration on the Command Line
2.1 Using php -v
- Explanation: The php -v command is the simplest way to check the current PHP version.
Command:
$ php -v
- Expected Output:
- Troubleshooting: If the command returns “command not found,” PHP might not be installed or available in your PATH. To resolve this, ensure PHP is installed and update the PATH variable if necessary.
2.2 Using php -i for Detailed Configuration
- Explanation: This command displays detailed PHP information, similar to
phpinfo()
Command:
$ php -i
- Expected Output: Displays PHP configuration details, extensions, loaded modules, and settings.
Tip: Redirect output to a file for easy reading:
$ php -i > php_info.txt
2.3 Using php –ini to Find the Loaded Configuration File
- Explanation: Locates the path to the main PHP configuration file (php.ini).
Command:
$ php --ini
- Expected Output:
- Usage: To edit PHP settings, modify the php.ini file and reload PHP.
2.4 Checking PHP Modules with php -m
- Explanation: Displays active PHP modules (extensions).
Command:
$ php -m
- Output: Lists extensions like mysqli, curl, mbstring, etc.
2.5 Advanced Check: Displaying Specific Configuration Values with php -r
- Explanation: Check individual settings.
Command:
$ php -r 'echo ini_get("upload_max_filesize");'
3. Checking PHP Version and Configuration Using PHP Scripts
3.1 Creating a phpinfo() Script
- Explanation: Displays PHP details in a browser.
Script:
<?php
phpinfo();
?>
- Security Note: Remove or restrict this file after checking.
3.2 Checking Specific Configuration Values with Custom PHP Scripts
- Explanation: Create scripts to show only specific settings.
Script:
<?php
echo 'Upload Max Filesize:.' ini_get('upload_max_filesize') . '<br>';
?>
4. Using the Hosting Control Panel to Check PHP Version and Configuration
With control solutions such as cPanel and DirectAdmin, making changes to PHP settings is very convenient. One advantage would be viewing or altering examples of PHP without returning to the command line. There is a gloomy interface for viewing specific configuration information and globally specific PHP settings for a general PHP understanding of its configuration details, which is suitable for users who require complicated technical operations.
4.1 cPanel
- PHP Selector Tool: Use this to change PHP versions.
- MultiPHP Manager: Manage PHP versions per domain.
- Access PHP Settings: Change values like memory_limit and upload_max_filesize.
To learn more about changing PHP versions in cPanel, refer to our detailed article: How to Change PHP Version in cPanel.
4.2 DirectAdmin
Changing the PHP version and viewing configuration details is also straightforward for users with DirectAdmin. DirectAdmin provides an intuitive PHP version management feature similar to cPanel’s PHP Selector. You can use this tool to choose the PHP version that best meets your website’s requirements.
To learn more about changing PHP versions in DirectAdmin, refer to our detailed article: How to Change PHP Version in DirectAdmin.
5. Checking PHP Configuration in CMS Environments
5.1 WordPress
Using Plugins:
Using plugins in WordPress provides an easy way to check the PHP version and other server configuration details. Plugins like “Site Health” or “PHPInfo” offer insights directly from the WordPress dashboard without requiring technical expertise in server management. The “Site Health” plugin, accessible under the “Tools” menu, provides information on the server environment, including Pthe HP version, memory limits, maximum upload size, and execution time limits. These details are essential for troubleshooting compatibility issues with themes or plugins and ensuring your server environment aligns with WordPress recommendations for optimal performance and security. Regularly checking these values can help maintain a stable and compatible WordPress site.
6. How to Interpret PHP Configuration Values
Common Settings:
- Memory_limit:
This setting specifies the maximum number of bytes a PHP script can use as memory. This feature assists in stopping scripts from utilizing all the disk space on the server, which can result in system hang-ups or slowdowns. This value may have to be augmented for resource-intensive applications, but usage must be closely watched to prevent the server from being overwhelmed. If no limit is specified, this directive can be set to -1, which means no limit can be imposed, which is dangerous in shared environments.
- upload_max_filesize:
This parameter limits the maximum size of uploaded files using PHP scripts. If you let users upload image or video files, this value must be set according to the expected file sizes. Smaller a value might prevent users from uploading at all, while too high a value is risky or could result in excessive server consumption.
post_max_size:
This setting defines the maximum size for POST data, including form submissions and file uploads. This value should exceed upload_max_filesize for larger files, as it encompasses all POST data sent to the server. If post_max_size is set too low, it might result in incomplete data being processed for applications that rely on extensive form submissions.
max_execution_time:
It specifies the maximum time (in seconds) a PHP script can take to run. It prevents poorly written scripts from running forever and using the server’s resources. This might be true if one needs to run more complex operations, such as importing an extensive database or other intensive data processing tasks. If set too high, the load on the server can increase because scripts do not complete successfully.
7. Troubleshooting Common Issues with PHP Version and Configuration Checks
- PHP Command Not Found:
This issue occurs when the system cannot locate the PHP executable. It often happens if PHP is not installed or the system’s PATH variable doesn’t include PHP’s directory. To fix this, verify that PHP is installed using package managers like apt, yum, or brew, depending on the operating system. After installation, confirm that PHP’s location is added to the PATH environment variable. This step enables commands like php -v to work from any terminal session.
- Incorrect PHP Version Displayed:
Sometimes, systems install multiple PHP versions, leading to version conflicts. When you run php—v, the system might show an unintended version if both versions are managed differently (e.g., one from the OS package manager and one from a custom installation). To solve this issue, set the complete path towards the preferred PHP variant or the desired version default. Other methods to set the PHP version of choice on Linux include update alternatives.
8. Additional Tools for Checking PHP Version and Configuration
- Composer:
Composer is a dependency manager for PHP, frequently used to install packages and manage project dependencies. Running
$ composer --version
provides information about the installed Composer version, which can be necessary for compatibility checks when working with many PHP frameworks and libraries. Composer checks the PHP version as part of its dependency validation, helping us ensure that required PHP configurations are met before installing packages.
9. Summary and Best Practices
The article’s sections show how to test their PHP versions and configurations on various servers. Periodically checking the frequently updated PHP version and necessary configuration settings helps achieve and sustain website security, stability, and compliance with your applications. Following the PHP releases and maintaining notifications about settings like memory_limit and upload_max_filesize allows you to have a server environment suitable for modern web technologies. In this way, you have the impression that you’re helping tune your server to run better, and the consequences will affect developers and end users exceptionally positively.
About the writer
Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.
Melvina
Wonderful post! We are linking to this particularly great post on our site.
Keep up the great writing.