How to Fix WordPress 5.6 PHP Version 8.0 Plugin Installation Error

How to Fix WordPress 5.6 PHP Version 8.0 Plugin Installation Error

I ran into an interesting error while trying to setup a local development instance of WordPress 5.6 as back-end for a Gatsby.js project.

Bug Symptoms

You have PHP version 8.0 and WordPress version 5.6 or above. You are unable to install any WordPress Plugins either via the Admin Panel or via manual plugin upload.

Bug Confirmation

You check the server logs... in my case it's the Apache2 error.log and see something similar to the following:

PHP Fatal error:  Uncaught ValueError: fread(): Argument #2 ($length) must be greater than 0

Bug Cause

There's an issue with the fread() method on the PclZip library that WordPress uses to handle the decompress zip files when the zip contains 0 length files. You can read more about the issue here. Luckily, PclZip is only used as a fall back when PHP's native zip extension is disabled, so there's an easy solution.

Bug Fix

Install the PHP Zip extension, make sure it's the correct version and restart or reload the server.

In my case, since I am on my local environment it's as simple as using apt-get and restarting Apache2.  

sudo apt-get install php8.0-zip
sudo service apache2 restart
info.php zip activated

If you are hosted, make sure to contact your host provider about enabling the zip extension for PHP.

Double check that Zip is enabled with info.php and you are good to go.

Show Comments