谷歌云Compute Engine安装Mcrypt扩展后仍报错求助
Hey there, I’ve dealt with this exact headache a few times when working with older CodeIgniter versions and PHP 7.0. Let’s walk through the fixes step by step:
Verify if Mcrypt is actually enabled
Installing the package doesn’t always mean it’s loaded by PHP. Run this terminal command to check your CLI PHP setup:php -m | grep mcryptIf "mcrypt" doesn’t show up, the extension isn’t enabled. Also, create a quick
phpinfo.phpfile in your web root:<?php phpinfo(); ?>Access it via your browser and search for "mcrypt"—if it’s missing, your web server’s PHP config is using a different ini file than the CLI version, and the extension isn’t loaded there.
Manually enable the Mcrypt extension
First, find your PHP 7.0 configuration file path:php --iniLook for the "Loaded Configuration File" line. Open that file with a text editor (like nano):
sudo nano /path/to/your/php.iniSearch for a line like
;extension=mcrypt.so(the semicolon means it’s commented out). Remove the semicolon to uncomment it, save the file, and exit.Restart the correct service (not just the instance)
Restarting your GCE instance doesn’t always trigger a reload of PHP or your web server. Use the right command for your setup:- For Apache:
sudo systemctl restart apache2 - For Nginx + PHP-FPM:
sudo systemctl restart php7.0-fpm sudo systemctl restart nginx
This ensures the updated PHP config takes effect.
- For Apache:
Alternative: Switch to OpenSSL (more future-proof)
Mcrypt is deprecated in PHP 7.1+ and removed in later versions, so switching to OpenSSL is a smarter long-term fix. In your CodeIgniterapplication/config/config.php:$config['encryption_driver'] = 'openssl';Confirm OpenSSL is enabled with
php -m | grep openssl—it’s usually enabled by default in PHP 7.0.
After trying these steps, reload your CodeIgniter site—this should resolve the error.
内容的提问来源于stack exchange,提问作者parth

