Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function utf8_decode

Tags:

php

php-7

I looked at other SO answers here and here about this error: FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function utf8_decode

Both answers say that installing php-xml will fix the error. But that didn't work. I ran sudo apt install php-xml which installed both php-xml and php7.0-xml and I restarted php-fpm and nginx. But I still get the same error.

Also checked function_exists('utf8_decode') and it returns false. So the error is obviously thrown when utf8_decode is called.

The server is Ubuntu 16.04 and PHP 7.0. Here's the phpinfo output (PDF): https://drive.google.com/file/d/0B3GpdAvwm4fOaWMwb0JkTFQyb0U/view?usp=sharing

like image 575
tinkerr Avatar asked Oct 02 '17 18:10

tinkerr


2 Answers

OK so I figured it out. This was related to missing files in /etc/php/7.0/mods-available/

Normally there should be an xml.ini file there but that file was missing because of how I had installed, uninstalled and re-installed PHP. That operation was not done cleanly. After installing PHP from the PPA I had uninstalled it, deleted many files from /etc/php/ (which is not recommended. Use apt-get purge instead).

So long story short, this worked:

sudo apt-get purge php-xml php7.0-xml

sudo apt-get install php-xml

like image 169
tinkerr Avatar answered Oct 04 '22 12:10

tinkerr


Run php -v to check the version of PHP.

If you're running version is 5.6, the solution is as follows:

sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml

Otherwise, run the following:

sudo apt-get install php7.2-mbstring php7.2-mcrypt php7.2-mysql php7.2-xml
like image 35
Ricardo Luis Zuluaga Salazar Avatar answered Oct 04 '22 12:10

Ricardo Luis Zuluaga Salazar