Class imagick not found when ran from CLI - php

$im = new imagick($file);
This line of code will work fine when ran from my browser, but when I try to run it from command line (CLI) then I get the following error...
Class 'imagick' not found
Any ideas why it won't work from CLI?

Found a solution:
sudo aptitude install make php5-dev php-pear
sudo aptitude remove php5-imagick
sudo aptitude install libmagick9-dev
sudo pecl install imagick
sudo /etc/init.d/apache2 restart
http://kvz.io/blog/2008/02/27/class-imagick-not-found/

The php cli executable is seperate(as in, a seperate binary file) from what generally gets run through a webserver. So, they can be totally different php versions, with different php.ini files and different extensions compiled in/enabled.

Run "php -i | grep include_path" and make sure that class file path is in there. If not, you can either add it in your script or your environment (bash profile).

Related

How to enable php5 curl on Ubuntu 14.04?

I have installed curl on Ubuntu 14.04 running PHP 5.6 with the following commands:
sudo apt-get install php5-curl
sudo service apache2 restart
It returns a successful message, but when I run:
php -m
the curl module is not listed, and phpinfo(); does not recognize it as installed or active. I also tried adding:
extension=curl.so
to my php.ini file, but that had no effect. How do I get PHP to recognize that curl is installed?
I got it working based on the second answer listed here: https://askubuntu.com/questions/9293/how-do-i-install-curl-in-php5
Basically:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5.6-curl
sudo service apache2 restart
I'm not really sure what made the difference. The repository reference is the most significant difference from previous attempts, but it seems odd as prior installation attempts didn't appear to have any problem accessing or installing/updating php-curl. And I had made sure everything was updated several times. But whatever it was, the above resolved it.
ssh to your server and cd to /
find / -name 'curl.so'
Run the above find command to locate where the curl binary is hanging out at. If you can't find the file, you might need to install curl and run the find command again.
apt-get install php5-curl
You'll now want to edit the php.ini being used for php files run from the cli (it's different than the one used by apache), and is likely at /etc/php5/cli/php.ini
nano /etc/php5/cli/php.ini
You can also run
php -i | grep 'php.ini'
To get the file path, just to be sure.
In your php.ini file search for [curl] by pressing ctrl + w
You'll now want to add the extension to the file and it should look something like the following, though your path to the curl.so file and such might be a little different:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =
extension=/usr/lib/php5/20131226/curl.so
After doing the above, I was able to use curl in php scripts run from the cli.

Laravel 4.2 + Laravel + PHP 7 +Ubuntu= Mcrypt PHP extension required [duplicate]

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

Installing curl to PHP cli

I'm trying to set up a cronjob which requires curl, and I'm calling it directly from crontab with
* * * * * /usr/bin/php myurl/my_cron.php
The problem is, it looks like the curl module isn't installed for my phpcli.
It works just fine when I hit the url from my browser, but when I run
php -q myfile.php
from the command line, it returns
PHP Fatal error: Call to undefined function curl_init() in my_cron.php on line 20
When I run php -m the curl module does not show up. However when I go to the browser and dump the php_info(), the module shows up and says its correctly installed.
The other kicker is i've been trying to install curl with apt-get onto the server (Ubuntu 12.04 php 5.4), it seems to take down my PHP as it begins to simply attempt to download the index.php file wherever I try to browse to.
Here are the attempts I've made to install curl that have taken down PHP:
sudo apt-get install php-curl
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
After each of these I restarted the apache2 server and still no dice, it attempted to download the file instead of opening the page.
How can I install php5-curl to just the cli, so that my server can run it and I don't have to go through a browser?
The other possibility is I could run the cronjobs through wget from the crontab file, but I've heard that's not the best option and potentially unreliable.
Any help is much appreciated. Thanks!
I had the same issue. But, finally I solved it by running the following command.
sudo apt-get install php7.0-curl
Restart the server after installing. This answer may not be useful for the user who asked because he asked it two months ago. But, this may be useful for the users who reading this in the future.
Here's how I've fixed this on ubuntu 14.04 when curl was working in php files run through apache, but not when called from the cli.
ssh to your server and cd to /
find / -name 'curl.so'
Run the above find command to locate where the curl binary is hanging out at. If you can't find the file, you might need to install curl and run the find command again.
apt-get install php5-curl
You'll now want to edit the php.ini being used for php files run from the cli (it's different than the one used by apache), and is likely at /etc/php5/cli/php.ini
nano /etc/php5/cli/php.ini
You can also run
php -i | grep 'php.ini'
To get the file path, just to be sure.
In your php.ini file search for [curl] by pressing ctrl + w
You'll now want to add the extension to the file and it should look something like the following, though your path to the curl.so file and such might be a little different:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =
extension=/usr/lib/php5/20131226/curl.so
After doing the above, I was able to use curl in php scripts run from the cli.
first find the version of your php cli by:
php -v
for example if it was version 7 then:
sudo apt-cache search php7
this will give you the proper module names for your current version:
php7.0-curl - CURL module for PHP <---- the name of curl module.
php7.0-dev - Files for PHP7.0 module development
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
php7.0-json - JSON module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-mysql - MySQL module for PHP
.
.
so on
so to add curl support, copy the name of curl module from the list above then do the following:
sudo apt-get install php7.0-curl
If you are using the command-line interface ('cli') for php5, instead of
php -q myfile.php
please use:
php5 -q myfile.php
php5-curl seems to enable the curl module for the cli php5 and not php and both (can) load different configurations and modules.
I use ubuntu 14.04 and php 5.3. After upgrading to php 5.6.29 I also has problem with php curl. My directory structure after updating to php 5.6.29:
/etc/php5 - old version (5.3)
/etc/php/5.6 - new version
The next command
sudo apt-get install php5-curl
didn't help (looks like it connects to old php version - 5.3).
I have found next article: php 5.6 for magento
It advice to use command
apt-get -y install php5.6-curl
instead of
apt-get -y install php5-curl
It works for me!
The first thing you should always check is your php.ini file. You should have a php.ini file in your web root. Curl is installed by default on most web servers; I haven't found a web server with PHP that hasn't already had curl installed. Its not always enabled, though.
Check your your php.ini file and search for php_curl.dll, it should look like this:
;extension=php_curl.dll
Just remove the semicolon (;) from before "extension" and save the file. It should work right away. According to your phpinfo.php its already installed, so it likely just needs to be enabled.
A similar question can be found here if you're interested: Call to undefined function curl_init()
In case someone reached here to find windows version of running curl.
Open php.ini and remove the ; before extension=php_curl.dll around line 656.
I am pretty much sure what Apache loads is C:\wamp\bin\apache\Apache2.2.17\bin\php.ini therefore you may find curl working from browser.
But when php is run from command line then it may show unknown function curl_init();
Run php -r "echo php_ini_loaded_file();" in the command line to see which ini file is being loaded.
Usually its found inside C:\wamp\bin\php\php5.3.5\php.ini its a different file from what Apache is using. So open it and then remove the ; before extension=php_curl.dll around line 656.
Hope it helps someone.

Laravel requires the Mcrypt PHP extension

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

call to undefined function mb_strimwidth

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

Categories