Skip to content

elektrischerwalfisch/php-version-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

PHP Version Checker for Shared Hosting

A PHP script that automatically detects available PHP versions on shared hosting environments where different PHP versions can be activated via .htaccess handlers.

🎯 Purpose

Most shared hosting providers offer multiple PHP versions but don't always clearly document which versions are available or how to activate them. This tool automatically tests common PHP handlers to show you:

  • Which PHP versions are actually available on your server
  • The correct .htaccess syntax to use each version
  • Your current PHP configuration details

🚀 Features

  • Automatic Detection: Tests common PHP handler patterns automatically
  • Safe Testing: Creates temporary isolated directories for testing
  • Clean Results: Shows working PHP versions with ready-to-use .htaccess examples
  • WordPress Safe: Designed to work alongside WordPress installations
  • No Dependencies: Pure PHP, no external libraries required
  • Self-Cleaning: Automatically removes temporary test files

📋 Requirements

  • PHP 5.6 or higher
  • Web server with .htaccess support (Apache)
  • Basic file system permissions (ability to create directories and files)
  • Either cURL extension or allow_url_fopen enabled

🛠️ Installation

  1. Download the check.php file
  2. Upload it to your web server
  3. For safety, create a subdirectory like /checkphp/ and place the file there
  4. Access the file via your web browser

Directory Structure Example

/your-website/
├── .htaccess (your main site)
├── index.php (your main site)
├── checkphp/
│   └── check.php
└── other-files...

🖥️ Usage

  1. Upload the script to your web server
  2. Navigate to the script in your web browser:
    https://yourdomain.com/checkphp/check.php
    
  3. Review the results - the script will show:
    • Your current PHP version
    • All available PHP versions on the server
    • Ready-to-use .htaccess examples

Example Output

✓ x-httpd-php74 → PHP 7.4.33
✓ x-httpd-php80 → PHP 8.0.30
✓ x-httpd-php81 → PHP 8.1.27
✗ x-httpd-php82 → Not available

📝 How to Use the Results

Once you know which PHP versions are available, you can switch PHP versions for any directory by creating or modifying the .htaccess file in that directory.

Example: Switch to PHP 8.1

Create or edit .htaccess in your target directory:

AddHandler x-httpd-php81 .php

Example: WordPress with PHP 8.0

In your WordPress directory's .htaccess:

# PHP Version
AddHandler x-httpd-php80 .php

# BEGIN WordPress
RewriteEngine On
RewriteBase /
# ... rest of WordPress rules
# END WordPress

🔧 How It Works

The script uses a smart testing approach:

  1. Creates a temporary test directory with a unique name
  2. Generates a simple PHP test file that outputs PHP_VERSION
  3. Tests each common handler by:
    • Creating a .htaccess file with the handler
    • Making an HTTP request to the test file
    • Checking if a valid PHP version is returned
  4. Cleans up automatically by removing all temporary files
  5. Displays results with working handlers and their versions

Tested Handler Patterns

The script tests these common patterns:

  • x-httpd-php56 through x-httpd-php84
  • application/x-httpd-php56 through application/x-httpd-php84

🛡️ Security & Safety

  • No system modifications: Only creates temporary files for testing
  • Self-contained: All testing happens in isolated temporary directories
  • Auto-cleanup: Removes all temporary files automatically
  • WordPress safe: Won't interfere with existing .htaccess files
  • Read-only approach: Doesn't modify any existing server configuration

🔍 Troubleshooting

"No versions found"

  • Your hosting provider might use different handler names
  • PHP execution might be restricted
  • Check with your hosting provider for their specific PHP handler syntax

"exec() function is disabled"

  • This is normal on shared hosting for security reasons
  • The main testing functionality will still work via HTTP requests

Permission errors

  • Ensure the script has permission to create directories and files
  • Check your hosting account's file permissions

🎨 Customization

You can modify the $common_handlers array in the script to test additional or different handler patterns specific to your hosting provider.

📊 Use Cases

  • WordPress sites: Determine which PHP versions are available for optimization
  • Legacy applications: Check if older PHP versions are still supported
  • Migration planning: Assess available upgrade paths
  • Performance testing: Compare performance across different PHP versions
  • Hosting evaluation: Verify hosting provider's PHP version claims

🤝 Contributing

Found this useful? Consider:

  • Testing on different hosting providers
  • Adding support for additional handler patterns
  • Reporting issues or improvements
  • Sharing your results to help others

⚠️ Important Notes

  • Remove after use: Delete the script after checking (it's not needed permanently)
  • Backup first: Always backup your site before making PHP version changes
  • Test thoroughly: Test your applications with new PHP versions before going live
  • Monitor logs: Check error logs after switching PHP versions

📄 License

This project is open source. Feel free to modify and distribute as needed.

🙋‍♂️ Support

If you encounter issues:

  1. Check your hosting provider's documentation
  2. Verify file permissions
  3. Contact your hosting provider for their specific PHP handler syntax
  4. Check server error logs for additional information

Made for shared hosting environments where SSH access is limited but .htaccess flexibility is available.

About

PHP Version Checker for Shared Hosting

Topics

Resources

License

Stars

Watchers

Forks

Languages