A PHP script that automatically detects available PHP versions on shared hosting environments where different PHP versions can be activated via .htaccess
handlers.
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
- 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
- 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
- Download the
check.php
file - Upload it to your web server
- For safety, create a subdirectory like
/checkphp/
and place the file there - Access the file via your web browser
/your-website/
├── .htaccess (your main site)
├── index.php (your main site)
├── checkphp/
│ └── check.php
└── other-files...
- Upload the script to your web server
- Navigate to the script in your web browser:
https://yourdomain.com/checkphp/check.php
- Review the results - the script will show:
- Your current PHP version
- All available PHP versions on the server
- Ready-to-use
.htaccess
examples
✓ 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
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.
Create or edit .htaccess
in your target directory:
AddHandler x-httpd-php81 .php
In your WordPress directory's .htaccess
:
# PHP Version
AddHandler x-httpd-php80 .php
# BEGIN WordPress
RewriteEngine On
RewriteBase /
# ... rest of WordPress rules
# END WordPress
The script uses a smart testing approach:
- Creates a temporary test directory with a unique name
- Generates a simple PHP test file that outputs
PHP_VERSION
- 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
- Creating a
- Cleans up automatically by removing all temporary files
- Displays results with working handlers and their versions
The script tests these common patterns:
x-httpd-php56
throughx-httpd-php84
application/x-httpd-php56
throughapplication/x-httpd-php84
- 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
- Your hosting provider might use different handler names
- PHP execution might be restricted
- Check with your hosting provider for their specific PHP handler syntax
- This is normal on shared hosting for security reasons
- The main testing functionality will still work via HTTP requests
- Ensure the script has permission to create directories and files
- Check your hosting account's file permissions
You can modify the $common_handlers
array in the script to test additional or different handler patterns specific to your hosting provider.
- 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
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
- 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
This project is open source. Feel free to modify and distribute as needed.
If you encounter issues:
- Check your hosting provider's documentation
- Verify file permissions
- Contact your hosting provider for their specific PHP handler syntax
- Check server error logs for additional information
Made for shared hosting environments where SSH access is limited but .htaccess
flexibility is available.