Diwali Cloud Dhamaka: Pay for 1 Year, Enjoy 1 Year FREE Grab It Now!
Knowing what version of PHP you are using and other settings is important for managing and supporting developed web applications. The available versions and configuration options, as well as changes to them, influence functionality, performance, and compatibility.
When making decisions concerning updates, installs, and settings, these factors would be crucial for anybody creating applications, managing systems, or just managing websites.
This tutorial will walk you through the process of using the command line to find the PHP version and configuration.
Let’s get started!
1. Open Terminal: You can find Terminal in your applications or search for it in the spotlight.
Run the PHP Version Command:
bash
Copy code
php -v
This command returns the PHP version along with additional information about the PHP build and configuration.
Example Output:
scss
Copy code
PHP 8.1.0 (cli) (built: Nov 25 2021 20:10:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
1. Open Command Prompt: Press Win + R, type cmd, and hit Enter.
Run the PHP Version Command:
bash
Copy code
php -v
2. You should see a similar output as on Linux/macOS.
The phpinfo() function provides comprehensive details about the PHP environment. It includes version, build date, configuration options, extensions, and more.
1. Create a New PHP File: Name it phpinfo.php and place it in your web server’s root directory (e.g., /var/www/html on Apache or public_html on shared hosting).
Insert the phpinfo() Function:
php
Copy code
phpinfo();
?>
2. Save the File.
3. Access the Script via Browser: Open your web browser and navigate to http://yourdomain.com/phpinfo.php.
You’ll see a detailed page displaying PHP version and configuration settings. Remember to delete this file after use to prevent exposing sensitive information.
The php -i command is useful for obtaining PHP configuration details directly from the command line.
1. Open Terminal.
Run the Command:
bash
Copy code
php -i
2. This outputs a configuration summary similar to phpinfo().
3. Open Command Prompt.
Run the Command:
bash
Copy code
php -i
Note: You might want to redirect the output to a file for easier viewing:
bash
Copy code
php -i > php-config.txt
1. Log in to cPanel.
2. Find the PHP Information Section: Usually under “Software” or a similar category.
3. View PHP Information: This section provides a comprehensive view of your PHP configuration.
1. Log in to Plesk.
2. Navigate to PHP Settings: Go to “Websites & Domains” > “PHP Settings”.
3. Review PHP Configuration: Plesk allows you to view and modify PHP settings from this interface.
Some common settings displayed by phpinfo() or php -i include:
- PHP Version: The version number of PHP installed.
- Loaded Configuration File: The path to php.ini, the main configuration file.
- Additional .ini files: Additional configuration files that are included.
- Extensions: Lists of compiled and loaded extensions, e.g., pdo, mbstring.
- Directives: Specific configuration settings such as memory_limit, upload_max_filesize, post_max_size, and max_execution_time.
1. Locate php.ini: The path is typically displayed in the output of phpinfo() or php -i.
Edit the File: Use a text editor to change settings. For example:
ini
Copy code
memory_limit = 256M
upload_max_filesize = 64M
2. Restart Web Server: After making changes, restart the web server to apply them.
For Apache:
bash
Copy code
sudo systemctl restart apache2
For Nginx:
bash
Copy code
sudo systemctl restart nginx
In some shared hosting environments, you can override PHP settings using a .htaccess file.
3. Create/Edit .htaccess: Place this file in your web root.
Add PHP Configuration Directives:
apache
Copy code
php_value memory_limit 256M
php_value upload_max_filesize 64M
- Ensure PHP is installed.
- Check the PATH environment variable.
- Verify phpinfo.php is accessible.
- Ensure PHP is running correctly and + are correct.
- Verify you’re editing the correct php.ini.
- Restart your web server after the changes.
To check your PHP version or PHP configuration is not complicated and should be done routinely as part of managing your web application. By utilizing the terminal, scripts, or server control panels, you can easily obtain some statistics and make suitable changes in order to maintain the optimal effectiveness and security of your PHP environment. Understanding PHP configuration setup is one of the fundamental steps you can take when managing your web environment whether when diagnosing problems or planning for an update.
Let’s talk about the future, and make it happen!
By continuing to use and navigate this website, you are agreeing to the use of cookies.
Find out more