Laravel requires the Mcrypt PHP extension
The web enabled extensions and command line enabled extensions can differ. Run php -m
in your terminal and check to see if mcrypt
is listed. If it's not then check where the command line is loading your php.ini
file from by running php --ini
from your terminal.
In this php.ini
file you can enable the extension.
OSX
I have heard of people on OSX running in to problems due to the terminal pointing to the native PHP shipped with OSX. You should instead update your bash profile to include the actual path to your PHP. Something like this (I don't actually use OSX so this might not be 100%):
export PATH=/usr/local/php5/bin:$PATH
Ubuntu
On earlier versions of Ubuntu (prior to 14.04) when you run sudo apt-get install php5-mcrypt
it doesn't actually install the extension into the mods-available
. You'll need to symlink it.
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
On all Ubuntu versions you'll need to enable the mod once it's installed. You can do that with php5enmod
.
sudo php5enmod mcrypt
sudo service apache2 restart
NOTES
- PHP 7.1 deprecated mcrypt and 7.2 has removed the mcrypt extension entirely
- Laravel 5.1 and later removed the need for mcrypt
How to enable php-Mcrypt extension in Laravel Homestead
Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.
First check what version the server is running with phpinfo();
Check the file /etc/nginx/sites-enabled/homestead.test
and look for this line:
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock.
In this case the version 5.6 has mcrypt installed, but 7.3 don't.
You can just replace the line
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
for
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
and then reload nginx with sudo nginx -s reload
.
Or set the php version on Homestead.yaml:
sites:
- map: homestead.test
to: /home/vagrant/code/public
php: "5.6"
And then run vagrant provision, it will change the nginx configuration for PHP 5.6.
Can laravel work without mcrypt?
No, Laravel really requires the MCrypt Extension.
You could, however, ask your hosting provider to install the MCrypt extension.
If you decide not to use Laravel, instead take a look at Symfony.
Symfony is another very powerful framework and Laravel makes use of quite some of Symfony's features.
Link: http://symfony.com/
Symfony doesn't require this plugin to be installed, however it requires the following plugins (but I assume those are installed at every hosting provider):
- PHP >= 5.3.3
- JSON enabled
- ctype needs to be installed
- The php.ini needs the date.timezone setting
I hope I helped you further :)
EDIT: Newer versions of Laravel don't need to have Mcrypt!
Related Topics
How to Sort an Array of Associative Arrays by Value of a Given Key in PHP
Pdo Prepared Inserts Multiple Rows in Single Query
Get Order Items and Wc_Order_Item_Product in Woocommerce 3
How to Generate Xml File Dynamically Using PHP
How to Convert an Array to Object in PHP
How to Get Body of a Post in PHP
How to "Flatten" a Multi-Dimensional Array to Simple One in PHP
Jquery Validate Remote Method Usage to Check If Username Already Exists
Convert from MySQL Datetime to Another Format With PHP
Convert PHP Array to JavaScript
How to Bind an Array of Strings With MySQLi Prepared Statement
How to Get File_Get_Contents() to Work With Https
PHP Does Not Display Error Messages
Multiple Inputs With Same Name Through Post in PHP