已启用php.ini中OpenSSL扩展但仍未加载的问题求助
Let’s work through this confusing problem where php -m shows OpenSSL is loaded, but extension_loaded('openssl') returns false (and Laravel throws its required extension error). Here’s what to check step by step:
1. Confirm which php.ini your runtime environment is using
The biggest culprit here is that PHP CLI (which runs php -m) and your application’s runtime (web server/PHP-FPM, or even a separate CLI instance) often use completely different php.ini files.
To find the exact php.ini your Laravel app is reading:
- Create a simple file named
info.phpwith this code:<?php phpinfo(); ?> - Run this file in the same context as your app: if it’s a web app, access it via your browser; if it’s a CLI script, run
php info.phpin the same terminal window you use for Laravel commands. - Look for the
Loaded Configuration Fileentry—this tells you the php.ini file your application is actually using. Chances are it’s not the one you modified earlier.
2. Enable OpenSSL in the correct php.ini
Once you’ve located the right php.ini file:
- Double-check that
extension=openssl(orextension=php_openssl.dllfor older PHP versions) has no leading semicolon (;) to uncomment it. - Update
extension_dirto use an absolute path (e.g.,extension_dir = "C:/xampp/php/ext"instead of just"ext"). Relative paths can cause resolution issues in different runtime contexts. - Confirm the
php_openssl.dllfile exists in the directory specified byextension_dir, and that it matches your PHP version exactly (x86 vs x64, PHP 7.x vs 8.x—mismatched files will fail to load silently).
3. Restart your web server/PHP service
Changes to php.ini won’t take effect until you restart the service running your PHP code:
- If using Apache, restart the Apache service via your control panel or Command Prompt (
net stop Apache2.4 && net start Apache2.4on Windows). - If using Nginx with PHP-FPM, restart both Nginx and the PHP-FPM service.
- For CLI scripts, close and reopen your terminal to ensure you’re using the updated configuration.
4. Rule out environment mismatches
- If you have multiple PHP installations on your system (e.g., a system-wide PHP and a XAMPP/WAMP PHP), run
where phpin Command Prompt to list all available PHP executables. Confirm which one your Laravel app is using (check your web server config or Laravel’s CLI setup). - Ensure the php.ini file you modified corresponds to the PHP executable your app relies on.
5. Verify extension loading in phpinfo()
After making changes and restarting, go back to info.php and search for "openssl". You should see a dedicated section with details about its version and configuration. If this section is missing:
- Check file permissions (rare on Windows, but ensure the
php_openssl.dllfile isn’t blocked by Windows Defender or restricted permissions). - Try temporarily disabling other non-critical extensions to rule out conflicts that might prevent OpenSSL from loading.
内容的提问来源于stack exchange,提问作者Lamine Mohammedi

