Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string.
Now, after some times, I tried to execute that same code and it went out with this error:
Fatal error: Call to undefined function mb_strimwidth() in ...
I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible?
But my main question is: how can I get the same result as mb_strimwidth()?
I thought to rewrite the function using a loop and mb_strwidth(), but ALL the functions in that mbstring.php file are empty.
All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring
You probably don't have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.
Apache needs to be restarted afterwards if you are using mod_php
Just got this issue, if you are using linux just install the package php-mbstringand restart Apache.
sudo apt-get install php-mbstring
sudo service apache2 restart
If you are using specific PHP version, you may need to run the following:
sudo apt-get install php7.x-mbstring
sudo service apache2 restart
Replace 7.x by the exact PHP version.
u need to install php-mbstring package try.
check php version
php -v
then check mbstring already install and enable
php -i | grep mbstring
if not installed run this command
sudo apt-get install php-mbstring
if you are php other version example : 7.1, 7.2, 7.0 based on
run command like this :
sudo apt-get install php7.1-mbstring
if you are using nginx server for run laravel .. then check nginx configration file which version u have loaded in conf file..
go to cd /etc/nginx/sites-available and open your configuration file..
if you are loading php7.2 version in nginx conf file..
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
then u need to install 7.2 mbstring package..
sudo apt-get install php7.2-mbstring
and restart apache2 server
sudo service apache2 restart
if you already installed mbstring then you have to call this extension on php.ini file.
First, detect where is your php-fpm.ini file or php.ini.
run command
php -i | grep php.ini
it returns you path of php.ini file.
for example
/etc/php.ini
then open file with VIM or another editor
vim /etc/php.ini
and then add mbstring extension to php.ini file
extension=mbstring.so;
finally, restart php-fpm
systemctl restart php-fpm
Related
I'm trying to install OpenCart but get the following warning:
"Warning: mCrypt extension needs to be loaded for OpenCart to work!"
Since I'm a noob on this, could someone point me in the right direction on how to solve this? Google don't really help me out here :(
Thanks!
I solved this issue by put in COMMENT the error message validation for mCrypt inside the file
/install/controller/install/step_2.php change inside private function validate()
//if (!function_exists('mcrypt_encrypt')) {
// $this->error['warning'] = $this->language->get('error_mcrypt');
//}
and voila
and after install this extension
Then, you may want to try this extension:
(https://www.opencart.com/index.php?rout ... n_id=35487)
So you said you have FTP access and you can edit php.ini.
If the server has mcrypt installed but not enabled then if you add:
extension=mcrypt.so
then save php.ini and upload, this should work.
Note that some servers don't load user's php.ini, instead they are looking for a .user.ini file in root folder.
I would suggest you, if my above answer doesn't help you to contact your hosting provider.
If you're using a linux system and you have access to the console, you can just activate the mcrypt module in the php.ini.
Type into your console:
$ sudo php5enmod mcrypt
This will enable the module. If you are using PHP 7 instead of PHP 5 use phpenmod instead.
If you get an error, install the module first with
$ sudo apt-get install php5-mcrypt
or for PHP 7 with
$ sudo apt-get install php7.0-mcrypt
After this you have to restart your webserver. Use this command for apache2
$ sudo service apache2 restart
or this command for nginx
$ sudo service nginx restart
If you dont have access to your terminal by any reason, it could be possible to enable it trough the control panel (cPanel, Plesk, ...). In the most cases it's a one-click activation and not really complicated.
In case you are using apache2 on ubuntu :
First try to enable mcrypt using command:
sudo phpenmod mcrypt
If mcrypt is not installed, install it using below commands for PHP
PHP 5.6 :
sudo apt-get install php5.6-mcrypt
PHP 7.0:
sudo apt-get install php5.6-mcrypt
Enable mcrypt after insatallation and restart apache
sudo phpenmod mcrypt
sudo service apache2 restart
The only solution that always works with me it to use PHP 5 & mySQL 5 (5.x anything)
And in the hosting, assign the php version 5 (outdated) to the website, also make sure that the database is mySQL (5.x)
Thanks
I have the following packages installed on Ubuntu 16.04:
apache2 2.4.18-2ubuntu3.1
php-gettext 1.0.11-2build1
gettext 0.19.7-2ubuntu3
php7.0 7.0.15-0ubuntu0.16.04.4
The only mention of gettext when I call phpinfo() is in the module authors section ("GetText = Alex Plotnick"), so I would assume that support has been compiled in correctly.
It seems that gettext isn't loaded properly into PHP, because the following code:
<?php
if ( false === function_exists('gettext') ) {
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
Does indeed print "You do not have the gettext library installed with PHP."
Apart from documentation, the only php-gettext files I have installed are:
/usr/share/php/php-gettext/gettext.inc
/usr/share/php/php-gettext/streams.php
/usr/share/php/php-gettext/gettext.php
I haven't really touched any php or apache config (apart from try and install icingaweb2)
Can anyone see what my issue could be?
Update
More debugging...
me#phoenix:~$ ls /etc/php/7.0/apache2/conf.d/
10-mysqlnd.ini 20-dom.ini 20-intl.ini 20-mbstring.ini 20-pdo_mysql.ini 20-wddx.ini 20-xmlwriter.ini
15-xml.ini 20-imagick.ini 20-ldap.ini 20-mysqli.ini 20-simplexml.ini 20-xmlreader.ini 20-xsl.ini
me#phoenix:~$ sudo a2dismod php5
ERROR: Module php5 does not exist!
me#phoenix:~$ sudo find / -name gettext.so
/usr/lib/php/20151012/gettext.so
/usr/lib/x86_64-linux-gnu/perl5/5.22/auto/Locale/gettext/gettext.so
It should work out of the box after installation. Have you restarted Apache? Try first sudo apache2ctl restart or sudo service apache2 restart on the terminal console. If both should not work on your system, try sudo /etc/init.d/apache2 restart.
Check if there does exist a file /etc/php/7.0/apache2/conf.d/20-gettext.ini (or similar path on your system) containing the line
extension=gettext.so
There must not be a semicolon prepended, otherwise it is commented out. Some installations may also configue that line within the basic php configuration file /etc/php/php/7.0/php.ini, however the debian derivate's way is to use extra files in the conf.d folder.
You can enable PHP modules (e.g. gettext) on the command line
sudo phpenmod -v 7.0 gettext
If this does not work, edit the configuration manually.
Finally restart your Apache service as described above.
Check also if Apache is running the expected PHP version 7.0 with the following line in your PHP page
echo phpversion();
You can enable / disable Apache2 modules from multiple installed PHP versions on the command line
sudo a2dismod php5
sudo a2enmod php7.0
sudo apache2ctl restart
I am trying to use the migrate function in Laravel 4 on OSX. However, I am getting the following error:
Laravel requires the Mcrypt PHP extension.
As far as I understand, it's already enabled (see the image below).
What is wrong, and how can I fix it?
Do you have MAMP installed?
Use which php in the terminal to see which version of PHP you are using.
If it's not the PHP version from MAMP, you should edit or add .bash_profile in the user's home directory, that is : cd ~
In .bash_profile, add following line:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
Edited: First you should use command cd /Applications/MAMP/bin/php to check which PHP version from MAMP you are using and then replace with the PHP version above.
Then restart the terminal to see which PHP you are using now.
And it should be working now.
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
To those that uses XAMPP 1.7.3 and Mac
Go to Terminal
Enter which php
If it says /usr/bin/php, then proceed to 3.
Enter sudo nano ~/.bash_profile (or sudo vim ~/.bash_profile if you know how to use it)
Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Ctrl+O then enter to save, then Ctrl+X to exit.
Type cd ~
type . .bash_profile
restart terminal.
Enter which php. If you did it right, it should be the same as the path in #4.
The reason for the mcrypt error is because your Mac uses its native php, you need to change it to the one xampp has.
P.S.
I'd recommend using MAMP for Laravel 4 for Mac users, this issue will get resolved along with the php file info error without a sweat, and the php version of xampp is so outdated.
For non MAMP or XAMPP users on OSX (with homebrew installed):
brew install homebrew/php/php56-mcrypt
Cheers!
Using Ubuntu, just
sudo php5enmod mcrypt
did the trick for me. You don't need to restart Apache since you need to use PHP just from the CLI.
In Ubuntu (PHP-FPM,Nginx)
sudo apt-get install php5-mcrypt
After installing php5-mcrypt
you have to make a symlink to ini files in mods-available:
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
enable:
sudo php5enmod mcrypt
restart php5-fpm:
sudo service php5-fpm restart
More detail
Getting Laravel working on Apache
PHP version : PHP 5.5.9
Ubuntu version : 14.04
i had a working laravel project on windows. when i copied it to ubuntu server , i started getting the mcrypt error. this after a lot of hours of trial and error
getting artisan command working
(if you are having mcrypt error while using artisan command line tool)
i did a lot of trial and error so each time i run the php5enmod command before, i had error messages. but on fresh install there was no error messages. after this step i got artisan command working
sudo rm /etc/php5/mods-available/mcrypt.ini
sudo apt-get purge php5-mcrypt
sudo apt-get install mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
fixing the browser error
(if you are having mcrypt error in browser when accessing local laravel index page)
sudo nano /etc/php5/apache2/php.ini
add the following line under the dynamically compiled extensions section of php ini
extension=mcrypt.so
restart the apache server , purge the laravel cache and everything working
For php-fpm installations on Ubuntu 14.04, the following worked for me :
sudo apt-get install php5-mcrypt
This will create mcrypt.ini file inside /etc/php5/mods-available/
Then
sudo php5enmod mcrypt
will create a symlink in: /etc/php5/fpm/conf.d/
Just restart php-fpm services
sudo service php5-fpm restart
For ubuntu try these steps if others are not working :
cd ~
sudo apt-get remove php5-mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 restart
Hope that will help. Thanks !
Or, use:
sudo apt-get install php5-mcrypt
not sure if this will work on standard PHP installs - I installed php 5.5.7 using the package from :
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
This solved it for me on my Linux Mint local enviroment https://askubuntu.com/questions/350942/cannot-get-mcrypt-for-php5
I needed to make a symlink to my /etc/php5/conf.d/mcrypt.ini file in the following folders /etc/php5/apache2/conf.d/mcrypt.ini and /etc/php5/cli/conf.d/mcrypt.ini
My OS is Yosemite.
I resolve this issue, by finding configuration paths:
php --ini
Example output:
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed: (none)
Next steps:
Rename or Delete php55 ini file
Create symlink
Restart Apache server
Commands:
mv /usr/local/etc/php/5.5/php.ini /usr/local/etc/php/5.5/php.ini.default
ln -s /etc/php.ini /usr/local/etc/php/5.5/php.ini
sudo apachectl restart
Then you can check your php modules via:
php -m
Just for yumers,
yum install php-mcrypt
service httpd restart
chown -R apache:apache apppath
Maybe you need install remi repo
You need an all in one environment. You may use MAMP or XAMPP or any other tools. After installing one of these tools you will need to edit(create) your .bash_profile(Assuming that you use bash).
Or even simple and more professional you can use Laravel Homestead.
Here is a link to official documentation: http://laravel.com/docs/5.0/homestead
Also Jeffrey has a free tutorial about it:
https://laracasts.com/series/laravel-5-fundamentals/episodes/2
I advice you to go with homestead because you will preinstall all of the following tools.
Ubuntu 14.04
PHP 5.6
HHVM
Nginx
MySQL
Postgres
Node (With Bower, Grunt, and Gulp)
Redis
Memcached
Beanstalkd
Laravel Envoy
Fabric + HipChat Extension
For those who still come here today:
Laravel does not need mcrypt extension anymore. mcrypt is obsolete, the last update to libmcrypt was in 2007. Laravel 4.2 is obsolete too and has no more support. The best (=secure) solution is to update to Laravel 9.x+ (Laravel 8.x is still okay. But if you are upgrading, then upgrade to the latest version).
Mcrypt was removed from Laravel in June 2015: https://github.com/laravel/framework/pull/9041
Expanding on #JetLaggy:
After trying again and again to modify .bash_profile with the MAMP directory, I changed the file permissions for the MAMP php directory and was able to get 'which php' to show the proper directory. Trouble was that other functions didn't work, such as 'php -v'.
So I updated MAMP. http://documentation.mamp.info/en/mamp/installation/updating-mamp
This did the trick for my particular setup. I had to adjust my PATH to reflect the updated version of PHP, but once I did, everything worked!
On OS X
Using MAMP
Enter the command which php in the terminal to see which version of PHP you are using. If it's not the PHP version from MAMP, the $PATH variable used by Bash will need to be updated.
First, you should use command "cd /Applications/MAMP/bin/php" to check which php version from MAMP and take note of the version (eg, php5.6.7).
Once you know the version, you should edit the ~/.bash_profile file (that is, the .bash_profile that is in your home directory) and add an export line:
export PATH=/Applications/MAMP/bin/php/php5.6.7/bin:$PATH
Make sure that you replace php5.6.7 with the version of PHP that you have selected in MAMP.
Once the file has been saved, make sure that you close close your Terminal and open it again. Once that has been done, you will be using the PHP that ships with MAMP.
One way to easily find what the line should be that you need to put inside your .bash_profile is to run the following command inside your terminal:
echo export PATH=`cat /Applications/MAMP/conf/apache/httpd.conf \
| grep php | grep -i LoadModule | head -n1 \
| sed -e 's/^[^\/]*\/\(.*\)\/mod.*/\/\1/'`/bin:\$PATH
Copying and pasting those three lines into your terminal will correctly output the PHP version that has been selected inside the MAMP control panel.
Using Homebrew/MacPorts
Make sure that your path contains /usr/local/bin/ (Homebrew) or /opt/local/bin (MacPorts) if you are using PHP that comes with either of these two package managers.
Checking the PHP path with MacPorts
You can find the exact location of PHP using MacPorts with the following command:
port contents php70 | grep bin/php
Note that you should replace php70 with the version of PHP that you have installed.
Check the PHP path with Homebrew-php
Homebrew-php (https://github.com/Homebrew/homebrew-php) is a tap that has various different versions of PHP.
You can find the exact location of PHP using Homebrew with the following command:
brew --prefix homebrew/php/php56
Note that you should replace php56 with the version of PHP that you have installed.
in Ubuntu 14.04
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
Ubuntu 16.04
sudo apt-get install php-mcrypt
sudo phpenmod mcrypt
Ubuntu 18.04
sudo apt install php7.0-mcrypt
sudo phpenmod mcrypt
or
sudo apt install php7.2-mcrypt
sudo phpenmod mcrypt
If you are using Z Shell, just do the following:
Open terminal
sudo nano ~/.zshrc
Paste this; export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH
Save
Run source ~/.zshrc
Run which php - you should get the MAMP 5.6.10 path
5.6.10 is the version of PHP you set in your MAMP.
OSX with brew
$ brew install mcrypt php70-mcrypt
I am running PHP 7.0.x, so change "php70" to your version, if you are using a different version.
As stated in other answers, you can see your php version with $ php -v.
sudo php install mcrypt
sudo php5enmod mcrypt
I am trying to use the migrate function in Laravel 4 on OSX. However, I am getting the following error:
Laravel requires the Mcrypt PHP extension.
As far as I understand, it's already enabled (see the image below).
What is wrong, and how can I fix it?
Do you have MAMP installed?
Use which php in the terminal to see which version of PHP you are using.
If it's not the PHP version from MAMP, you should edit or add .bash_profile in the user's home directory, that is : cd ~
In .bash_profile, add following line:
export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
Edited: First you should use command cd /Applications/MAMP/bin/php to check which PHP version from MAMP you are using and then replace with the PHP version above.
Then restart the terminal to see which PHP you are using now.
And it should be working now.
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
To those that uses XAMPP 1.7.3 and Mac
Go to Terminal
Enter which php
If it says /usr/bin/php, then proceed to 3.
Enter sudo nano ~/.bash_profile (or sudo vim ~/.bash_profile if you know how to use it)
Then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Ctrl+O then enter to save, then Ctrl+X to exit.
Type cd ~
type . .bash_profile
restart terminal.
Enter which php. If you did it right, it should be the same as the path in #4.
The reason for the mcrypt error is because your Mac uses its native php, you need to change it to the one xampp has.
P.S.
I'd recommend using MAMP for Laravel 4 for Mac users, this issue will get resolved along with the php file info error without a sweat, and the php version of xampp is so outdated.
For non MAMP or XAMPP users on OSX (with homebrew installed):
brew install homebrew/php/php56-mcrypt
Cheers!
Using Ubuntu, just
sudo php5enmod mcrypt
did the trick for me. You don't need to restart Apache since you need to use PHP just from the CLI.
In Ubuntu (PHP-FPM,Nginx)
sudo apt-get install php5-mcrypt
After installing php5-mcrypt
you have to make a symlink to ini files in mods-available:
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
enable:
sudo php5enmod mcrypt
restart php5-fpm:
sudo service php5-fpm restart
More detail
Getting Laravel working on Apache
PHP version : PHP 5.5.9
Ubuntu version : 14.04
i had a working laravel project on windows. when i copied it to ubuntu server , i started getting the mcrypt error. this after a lot of hours of trial and error
getting artisan command working
(if you are having mcrypt error while using artisan command line tool)
i did a lot of trial and error so each time i run the php5enmod command before, i had error messages. but on fresh install there was no error messages. after this step i got artisan command working
sudo rm /etc/php5/mods-available/mcrypt.ini
sudo apt-get purge php5-mcrypt
sudo apt-get install mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
fixing the browser error
(if you are having mcrypt error in browser when accessing local laravel index page)
sudo nano /etc/php5/apache2/php.ini
add the following line under the dynamically compiled extensions section of php ini
extension=mcrypt.so
restart the apache server , purge the laravel cache and everything working
For php-fpm installations on Ubuntu 14.04, the following worked for me :
sudo apt-get install php5-mcrypt
This will create mcrypt.ini file inside /etc/php5/mods-available/
Then
sudo php5enmod mcrypt
will create a symlink in: /etc/php5/fpm/conf.d/
Just restart php-fpm services
sudo service php5-fpm restart
For ubuntu try these steps if others are not working :
cd ~
sudo apt-get remove php5-mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 restart
Hope that will help. Thanks !
Or, use:
sudo apt-get install php5-mcrypt
not sure if this will work on standard PHP installs - I installed php 5.5.7 using the package from :
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
This solved it for me on my Linux Mint local enviroment https://askubuntu.com/questions/350942/cannot-get-mcrypt-for-php5
I needed to make a symlink to my /etc/php5/conf.d/mcrypt.ini file in the following folders /etc/php5/apache2/conf.d/mcrypt.ini and /etc/php5/cli/conf.d/mcrypt.ini
My OS is Yosemite.
I resolve this issue, by finding configuration paths:
php --ini
Example output:
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed: (none)
Next steps:
Rename or Delete php55 ini file
Create symlink
Restart Apache server
Commands:
mv /usr/local/etc/php/5.5/php.ini /usr/local/etc/php/5.5/php.ini.default
ln -s /etc/php.ini /usr/local/etc/php/5.5/php.ini
sudo apachectl restart
Then you can check your php modules via:
php -m
Just for yumers,
yum install php-mcrypt
service httpd restart
chown -R apache:apache apppath
Maybe you need install remi repo
You need an all in one environment. You may use MAMP or XAMPP or any other tools. After installing one of these tools you will need to edit(create) your .bash_profile(Assuming that you use bash).
Or even simple and more professional you can use Laravel Homestead.
Here is a link to official documentation: http://laravel.com/docs/5.0/homestead
Also Jeffrey has a free tutorial about it:
https://laracasts.com/series/laravel-5-fundamentals/episodes/2
I advice you to go with homestead because you will preinstall all of the following tools.
Ubuntu 14.04
PHP 5.6
HHVM
Nginx
MySQL
Postgres
Node (With Bower, Grunt, and Gulp)
Redis
Memcached
Beanstalkd
Laravel Envoy
Fabric + HipChat Extension
For those who still come here today:
Laravel does not need mcrypt extension anymore. mcrypt is obsolete, the last update to libmcrypt was in 2007. Laravel 4.2 is obsolete too and has no more support. The best (=secure) solution is to update to Laravel 9.x+ (Laravel 8.x is still okay. But if you are upgrading, then upgrade to the latest version).
Mcrypt was removed from Laravel in June 2015: https://github.com/laravel/framework/pull/9041
Expanding on #JetLaggy:
After trying again and again to modify .bash_profile with the MAMP directory, I changed the file permissions for the MAMP php directory and was able to get 'which php' to show the proper directory. Trouble was that other functions didn't work, such as 'php -v'.
So I updated MAMP. http://documentation.mamp.info/en/mamp/installation/updating-mamp
This did the trick for my particular setup. I had to adjust my PATH to reflect the updated version of PHP, but once I did, everything worked!
On OS X
Using MAMP
Enter the command which php in the terminal to see which version of PHP you are using. If it's not the PHP version from MAMP, the $PATH variable used by Bash will need to be updated.
First, you should use command "cd /Applications/MAMP/bin/php" to check which php version from MAMP and take note of the version (eg, php5.6.7).
Once you know the version, you should edit the ~/.bash_profile file (that is, the .bash_profile that is in your home directory) and add an export line:
export PATH=/Applications/MAMP/bin/php/php5.6.7/bin:$PATH
Make sure that you replace php5.6.7 with the version of PHP that you have selected in MAMP.
Once the file has been saved, make sure that you close close your Terminal and open it again. Once that has been done, you will be using the PHP that ships with MAMP.
One way to easily find what the line should be that you need to put inside your .bash_profile is to run the following command inside your terminal:
echo export PATH=`cat /Applications/MAMP/conf/apache/httpd.conf \
| grep php | grep -i LoadModule | head -n1 \
| sed -e 's/^[^\/]*\/\(.*\)\/mod.*/\/\1/'`/bin:\$PATH
Copying and pasting those three lines into your terminal will correctly output the PHP version that has been selected inside the MAMP control panel.
Using Homebrew/MacPorts
Make sure that your path contains /usr/local/bin/ (Homebrew) or /opt/local/bin (MacPorts) if you are using PHP that comes with either of these two package managers.
Checking the PHP path with MacPorts
You can find the exact location of PHP using MacPorts with the following command:
port contents php70 | grep bin/php
Note that you should replace php70 with the version of PHP that you have installed.
Check the PHP path with Homebrew-php
Homebrew-php (https://github.com/Homebrew/homebrew-php) is a tap that has various different versions of PHP.
You can find the exact location of PHP using Homebrew with the following command:
brew --prefix homebrew/php/php56
Note that you should replace php56 with the version of PHP that you have installed.
in Ubuntu 14.04
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
Ubuntu 16.04
sudo apt-get install php-mcrypt
sudo phpenmod mcrypt
Ubuntu 18.04
sudo apt install php7.0-mcrypt
sudo phpenmod mcrypt
or
sudo apt install php7.2-mcrypt
sudo phpenmod mcrypt
If you are using Z Shell, just do the following:
Open terminal
sudo nano ~/.zshrc
Paste this; export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH
Save
Run source ~/.zshrc
Run which php - you should get the MAMP 5.6.10 path
5.6.10 is the version of PHP you set in your MAMP.
OSX with brew
$ brew install mcrypt php70-mcrypt
I am running PHP 7.0.x, so change "php70" to your version, if you are using a different version.
As stated in other answers, you can see your php version with $ php -v.
sudo php install mcrypt
sudo php5enmod mcrypt
I have a script that uses mcrypt_decrypt() function, but I get the following error
Fatal error: Call to undefined function mcrypt_decrypt()
What modules/libraries do I need to include to use this function? Or is there another reason I'm getting the error?
Thanks
sudo apt-get install php5-mcrypt
works on ubuntu.
Please see:
Mcrypt Requirements
Mcrypt Installation
You need to compile your PHP with --with-mcrypt[=DIR] and have libmcrypt Version 2.5.6 or greater on your machine.
Configure php5-mcrypt with php5-fpm (Ubuntu 14.04)
I’m going to assume you already have nginx and php-fpm installed and running.
php5-mcrypt should be installed already (it comes bundled with php5-fpm). Just for safety,
apt-get install php5-mcrypt
Create symlink to mods-avaliable,
ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
Enable it.
php5enmod mcrypt
Restart php-fpm,
service php5-fpm restart
Restart nginx,
service nginx restart
Done!
From the manual:
You need to compile PHP with the
--with-mcrypt[=DIR] parameter to enable this extension. DIR is the
mcrypt install directory. Make sure
you compile libmcrypt with the option
--disable-posix-threads.
Generally if PHP says a function is undefined, it means you need to compile in some library.
I above doesn't work, you can try this:
create mcrypt.ini file in /etc/php5/conf.d with content
extension=mcrypt.so
I upgraded PHP to 5.4 via http://php-osx.liip.ch/ and it worked.
for php 5.3.X
depends on availability of yum mcrypt package , you could use yum packeages
like this :
yum install php53-mcrypt
and restart httpd
And be carefull about the folder in the phpinfo page : "Scan this dir for additional .ini files" and the next : "Additional .ini files parsed ".
After upgrading to php 5.4 running (Works)
sudo php5enmod mcrypt
sudo service apache2 restart