I have a problem that I install ‘Archive_Zip 0.1.1’ on Linux server, but when I try to run the script to create the zip file it gives the fatal error
Fatal error: Class
ZipArchive
not found in …
where I put the code
$zip = new ZipArchive;
var_dump($zip);
$res = $zip->open($filename, ZipArchive::OVERWRITE);
if ($res !== TRUE) {
echo 'Error: Unable to create zip file';
exit;
}
if (is_file($src)) {
$zip->addFile($src);
} else {
// echo "<br>" . dirname(__FILE__) . $src;//'/install1';
if (!is_dir($src)) {
$zip->close();
@unlink($filename);
echo 'Error: File not found';
exit;
}
recurse_zip($src, $zip, $path_length);
}
$zip->close();
echo "<br>file name ".$filename;
but it doesn’t find the class file.
Please tell me the solution. What should I do to resolve the problem?
I also put php.ini
file to the folder where script is, but it does not work.
asked Oct 6, 2010 at 12:47
Parag ChaureParag Chaure
2,8532 gold badges19 silver badges26 bronze badges
6
For the ZipArchive
class to be present, PHP needs to have the zip extension installed.
See this page for installation instructions (both Linux and Windows).
On Debian and Ubuntu, you can usually install it with:
sudo apt update
sudo apt install php-zip
Then restart your webserver. Example:
sudo systemctl restart apache2
answered Oct 6, 2010 at 12:49
14
On Amazon ec2 with Ubuntu + nginx + php7, I had the same issues, solved it using:
sudo apt-get install php7.0-zip
answered May 6, 2016 at 6:56
DPPDPP
12.6k3 gold badges49 silver badges46 bronze badges
3
On ubuntu desktop, I had to do.
sudo apt-get install php5.6-zip
This installed the library but I still kept on getting the same error, so I had to restart apache using:
sudo service apache2 restart
and it worked.
answered Oct 28, 2016 at 12:10
Mubashar AbbasMubashar Abbas
5,4664 gold badges36 silver badges48 bronze badges
1
I’m not seeing it here, so I’d like to add that on Debian/Ubuntu you may need to enable the extension after installing the relative package. So:
sudo apt-get install php-zip
sudo phpenmod zip
sudo service apache2 restart
answered Oct 16, 2017 at 6:54
lorenzo-slorenzo-s
16.5k15 gold badges52 silver badges86 bronze badges
4
First of all, The solution for remote server:
If you are using cpanel you may have zip extension installed but not activate. You need to active it. For this case you need to go to cpanel > inside software section > click on PHP version. Then find zip and check it. Now save.
You should see like the image.
Refresh page. The error should disappear.
Note: If you dont found, contact server provider. They will install for you.
answered Nov 17, 2017 at 2:39
2
Centos 6
Or any RHEL-based flavors
yum install php-pecl-zip
service httpd restart
Abel Callejo
13.4k10 gold badges65 silver badges82 bronze badges
answered Oct 10, 2018 at 13:57
zzapperzzapper
4,6835 gold badges48 silver badges45 bronze badges
1
If you have WHM available it is easier.
Log in to WHM.
Go to EasyApache 4 (or whatever version u have) under Software tab.
Under Currently Installed Packages click Customize.
Go to PHP Extensions, in search type «zip» (without quotes),
you should see 3 modules
check all of them,
click blue button few times to finish the process.
This worked for me.
Thankfully I’ve WHM available.
answered May 15, 2018 at 11:36
temotemo
6121 gold badge9 silver badges25 bronze badges
1
For PHP 7.x
sudo apt-get install php-zip
For PHP 5.x
sudo apt-get install php5.x-zip
// (for example sudo apt-get install php5.6-zip)
And then restart the Apache server
sudo service apache2 restart
answered Dec 6, 2019 at 5:32
You also need to compile PHP with zip support. The manual says the following:
In order to use these functions you must compile PHP with zip support by using the —enable-zip configure option.
It’s not enough to simply install the correct extensions on the server. Have a look at the installation instructions link Pekka posted earlier. My answer is just a clarification of his.
answered Oct 6, 2010 at 13:08
JeremyJeremy
2,6511 gold badge21 silver badges28 bronze badges
3
This worked
apt-get install php7.0-zip
and no need to restart php7.0-fpm
manually.
Unpacking
php7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) …
Processing triggers forphp7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) …
php7.0-fpm
stop/waiting
php7.0-fpm
start/running, process 1572
php7.0-fpm
stop/waiting
php7.0-fpm
start/running, process 1777
Setting upphp7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) …
locale: Cannot setLC_ALL
to default locale: No such file or directoryCreating config file
/etc/php/7.0/mods-available/zip.ini
with new version
Processing triggers forphp7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) …
php7.0-fpm
stop/waiting
php7.0-fpm
start/running, process 2354
php7.0-fpm
stop/waiting
php7.0-fpm
start/running, process 2397
answered Mar 13, 2017 at 19:22
prostiprosti
41.3k14 gold badges182 silver badges149 bronze badges
I had the same issue with CentOS and cPanel installed server. I installed zipArchive package via cPanel and didn’t worked as expected.
After trying with so many fixes suggested each and everywhere just the below worked for me.
First find the name for the correct package with the below command
yum search zip |grep -i php
Then use the below code.
yum install your_zip_package_name_with_php_version
In my case correct code to install zipArchive was
yum install php-pecl-zip.x86_64
I had the solution from this link.
How can I inslatt zipArchive on PHP 7.2 with CentOS 7?
And this installation somehow enabled that package too and it also restarted the effecting services and after the completion of the execution of the above code zipArchive issue was gone.
answered Sep 2, 2018 at 9:52
PHP 5.2.0 and later
Linux systems
In order to use these functions you must compile PHP with zip support by using the —enable-zip configure option.
Windows
Windows users need to enable php_zip.dll inside of php.ini in order to use these functions.
answered Jul 1, 2013 at 11:39
V A SV A S
3,2784 gold badges33 silver badges38 bronze badges
For Centos 7 and PHP 7.3 on Remi
Search for the zip extension:
$ yum search php73 | grep zip
php73-php-pecl-zip.x86_64 : A ZIP archive management extension
The extension name is php73-php-pecl-zip.x86_64. To install it in server running single version of PHP, remove the prefix php73:
$ sudo yum --enablerepo=remi-php73 install php-pecl-zip #for server running single PHP7.3 version
$ #sudo yum --enablerepo=remi-php73 install php73-php-pecl-zip # for server running multiple PHP versions
Restart PHP:
$ sudo systemctl restart php-fpm
Check installed PHP extensions:
$ php -m
[PHP Modules]
apcu
bcmath
bz2
...
zip
zlib
answered Jan 7, 2020 at 3:51
kiatngkiatng
2,81832 silver badges39 bronze badges
0
I faced this issue on GCP while deploying wordpress in the App Engine Standard environment. This solved it :
sudo apt-get install php7.2-zip
answered Oct 18, 2019 at 3:55
Omar ShababOmar Shabab
5317 silver badges16 bronze badges
For me work, first review
php -m
php -version
Later install the extension
apt-get update
apt-get install php7.2-zip
systemctl restart apache2
answered Oct 14, 2020 at 22:01
DoberonDoberon
5748 silver badges19 bronze badges
If you are running into this error while using a Docker image and that you are calling the class properly, or that the error comes from an up-to-date library, then the zip
module is probably missing.
Assuming we use docker-compose
, we can confirm it’s missing by running docker-compose run php php -m
for instance and see that zip
is not listed.
To install it in your image, modify your Dockerfile
so it does the same as this example.
FROM php:7.3-apache
RUN set -eux
&& apt-get update
&& apt-get install -y libzip-dev zlib1g-dev
&& docker-php-ext-install zip
Then rebuild the image with docker-compose build php
and you are good to go.
answered Dec 9, 2020 at 8:43
CapripotCapripot
1,30215 silver badges25 bronze badges
For PHP 7.4 > The ZipArchive is not longer present by default and you need to install and configure it.
I strongly suggest using a library which you can just include in your project — like https://github.com/zanysoft/laravel-zip
This library is just a wrapper for the native ZipArchive
answered Sep 15, 2021 at 8:13
alex toaderalex toader
2,2701 gold badge17 silver badges19 bronze badges
For CentOS based server use
yum install php-pecl-zip.x86_64
Enable it by running: echo "extension=zip.so" >> /etc/php.d/zip.ini
answered Jan 7, 2020 at 11:10
WolfackWolfack
2,6471 gold badge26 silver badges50 bronze badges
You need to check the PHP version
If php version is 5.6 then , You need to install php5.7-zip
sudo apt-get install php5.6-zip
and then
sudo service apache2 restart
Hope it helps
answered May 12, 2020 at 5:16
SundarSundar
2532 silver badges6 bronze badges
I had the same issue and it had solved using two command lines:
sudo apt install php-zip
then reboot your web server, for Apache
sudo service apache2 restart
answered Mar 11, 2019 at 13:08
AboElnouRAboElnouR
2713 silver badges14 bronze badges
Try to write ZIPARCHIVE
instead of ZIPARCHIVE
.
answered Feb 9, 2020 at 12:27
URL87URL87
10.6k35 gold badges104 silver badges173 bronze badges
namespace
If you get this problem after adding namespace
you can use the global
namespace (backslash ):
$zip = new ZipArchive;
answered Jun 18, 2021 at 22:02
Mahdi BashirpourMahdi Bashirpour
16.7k12 gold badges115 silver badges143 bronze badges
CPanel [ Sharing Hosting ]
To fix this issue or error use the below steps:-
Error Details:-
/=========================================================================
An uncaught Exception was encountered
Type: Error
Message: Class 'ZipArchive' not found
Filename: /home/b2bvniowy1go/public_html/system/libraries/PHPExcel/Reader/Excel2007.php
Line Number: 85
Backtrace:
File: /home/b2bvniowy1go/public_html/dashboard/controllers/Brand_price.php
============================================================================ /
cPanel Version [ 94.0 (build 19) ]
Solution:- Do this changes to your remote server: Cpanel > Select PHP version section > extensions tab. Then find zip and check it. Now save.
answered May 4, 2022 at 9:23
1
The same in CMS Typo3 ver.11.5.8
while installing an extension by the Extension Manager,
nevermind that the Zip extension was installed in the cpanel.
The reason: in the .htaccess there was:
AddType application/x-httpd-php74 .php
AddHandler application/x-httpd-php74 .php
The fix: change the above by:
AddType application/x-httpd-alt-php74 .php .php7 .phtml
Now it’s working in me.
answered Feb 7 at 22:38
Don’t forget to use this class
use ZipArchive;
answered Mar 12 at 9:20
- Goto php.ini
- Search for zip
- Remove ‘;’ from that line (uncomment it)
answered May 23 at 9:41
1) You should require
your file with ZipArchive
file.
require 'path/to/file/ZipArchive.php';
2) Or use __autoload
method of class.
In PHP 5 it is a greate method __autoload().
function __autoload($class_name) {
require_once $class_name . '.php';
}
$obj = new MyClass1(); // creating an object without require.
http://www.php.net/manual/en/language.oop5.autoload.php
answered Oct 6, 2010 at 12:52
Alex PliutauAlex Pliutau
21.2k27 gold badges112 silver badges143 bronze badges
1
Download the repository and execute composer install on the directory, after create a test file, as next one
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require __DIR__.'/PhpSpreadsheet-develop/src/Bootstrap.php'; use PhpOfficePhpSpreadsheetIOFactory; $reader = new PhpOfficePhpSpreadsheetReaderXlsx(); $template = __DIR__."/templates/FLYAWAY_EN.xlsx"; $spreadsheet = PhpOfficePhpSpreadsheetIOFactory::load($template); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->getCell('B2')->setValue('John'); $worksheet->getCell('C2')->setValue('Smith'); $writer = PhpOfficePhpSpreadsheetIOFactory::createWriter($spreadsheet, 'Xls'); $writer->save('write.xls');
Answer by Cole Lim
Fatal error: Class ZipArchive not found in …,
Is it a server that you control? If so I believe it’s part of the make command when installing PHP. If it’s not a server that you control then the only option for you is to try to have the sys admin do it. Sorry I can’t be more precise-I’ve never installed PHP on a linux server from scratch.
– Jeremy
Oct 6 ’10 at 13:22
,If you are using cpanel you may have zip extension installed but not activate. You need to active it. For this case you need to go to cpanel > inside software section > click on PHP version. Then find zip and check it. Now save.,
Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers
On ubuntu desktop, I had to do.
sudo apt-get install php5.6-zip
This installed the library but I still kept on getting the same error, so I had to restart apache using:
sudo service apache2 restart
Answer by Rodney Brock
I got an error
Message: Class ‘ZipArchive’ not found
Filename: Reader/Excel2007.php
Line Number: 86,same error occurs
Message: Class ‘ZipArchive’ not found,Filename: Reader/Excel2007.php,Hi
I am attached PHPExcel/Reader/Excel2007.php
Excel2007.zip
var_dump(extension_loaded ('zip'));
Answer by Kaden Marin
While working on Zip file in your Laravel application, you might need to use PHP in-built class ZipArchive. When you use class in your controller file, you might get error «Class ‘AppHttpControllersZipArchive’ not found».,To use ZipArchive class in PHP, you need to have installed and enabled zip extension which is which uses libzip. You can simply install zip extension with your enabled PHP version.,Now refresh the page and error should have gone. If you still get the error, make use you have use class above else Laravel will try to find class in your Controllers directory.,
Share your Articles
Login
Register
PHP7.4
sudo apt-get install php7.4-zip
PHP8.0
sudo apt-get install php8.0-zip
And don’t forget to restart apache server to implement changes.
sudo service apache2 restart
Now refresh the page and error should have gone. If you still get the error, make use you have use class above else Laravel will try to find class in your Controllers directory.
<?php
namespace AppHttpControllers;
use ZipArchive;
/**
* Show the application homepage.
*
* @return IlluminateHttpResponse
*/
public function index()
{
...
$zip = new ZipArchive;
...
}
Answer by Alexis Bentley
Sorry — this was an issue with the automatic PHP update on Digital Ocean’s server which caused several issues.,You need to install and enable ZipArchive PHP extension in your server (http://php.net/manual/en/class.ziparchive.php). On https://www.phpdocx.com/faqs (1st item) you can read the needed PHP extensions to use phpdocx.
Today I am getting these errors :
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; fpdi_pdf_parser has a deprecated constructor in /home/username/lib/3rdParty/phpdocx-corporate-5.5/lib/fpdi/fpdi_pdf_parser.php on line 22
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; pdf_parser has a deprecated constructor in /home/username/lib/3rdParty/phpdocx-corporate-5.5/lib/fpdi/pdf_parser.php on line 51
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; pdf_context has a deprecated constructor in /home/username/lib/3rdParty/phpdocx-corporate-5.5/lib/fpdi/pdf_context.php on line 22
Fatal error: Uncaught Error: Class 'ZipArchive' not found in /home/username/lib/3rdParty/phpdocx-corporate-5.5/classes/CreateDocx.inc:634 Stack trace: #0 /home/username/lib/3rdParty/phpdocx-corporate-5.5/classes/CreateDocxFromTemplate.inc(46): CreateDocx->__construct('/home/planbuild...', 'resources/templ...') #1 /home/username/public_html/bp.php(97): CreateDocxFromTemplate->__construct('resources/templ...') #2 {main} thrown in /home/username/lib/3rdParty/phpdocx-corporate-5.5/classes/CreateDocx.inc on line 634
Answer by Harley Blackwell
Server Fault
help
chat
,
How to optimize on a fixed-cost based on number of results
,Please be sure to answer the question. Provide details and share your research!,Asking for help, clarification, or responding to other answers.
Try installing that and enabling it by running:
echo "extension=zip.so" >> /etc/php.d/zip.ini
Answer by Yahir Black
This error means that PHP could not find the ZipArchive class. Therefore, PHP needs to have the zip extension installed for the ZipArchive Class to be present.,Is your PHP saying that it cannot find the ZipArchive class? Then, this post will show you how to enable the ZipArchive module.,You can check whether ZipArchive is installed by using a PHP info file.,What does this error mean?
PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found
Answer by Musa Kerr
Error: Class ‘ZipArchive’ not found,After googling, found a hint that the zip extension has to be installed for zipArchive class to be present.,How to fix Uncaught Error Class ZipArchive not found,Home » Web Server » Uncaught Error Class ZipArchive not found – docxpresso plugin
Issue: Activating docxpresso plugin broke the website. Ah! my bad! After debugging, I could find the exact issue in error_log
.
PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found in /public_html/wp-content/plugins/docxpresso/CreateDocument.inc:87
Stack trace:
#0 /public_html/wp-content/plugins/docxpresso/plugin.php(67): DocxpressoCreateDocument->__construct(Array)
#1 /public_html/wp-includes/shortcodes.php(319): docxpresso_call(Array, '', 'docxpresso')
#2 [internal function]: do_shortcode_tag(Array)
#3 /public_html/wp-includes/shortcodes.php(197): preg_replace_callback('/\[(\[?)(docxpr...', 'do_shortcode_ta...', '[docxpresso fil...')
#4 /public_html/wp-includes/class-wp-hook.php(286): do_shortcode('[docxpresso fil...')
#5 /public_html/wp-includes/plugin.php(203): WP_Hook->apply_filters('[docxpresso fil...', Array)
#6 /public_html/wp-includes/post-template.php(240): apply_filters('the_content', '[docxpresso fil" while reading response header from upstream, client: 14.139.1.29, server: akshayaedu.com, request: "GET /testing-mathematical-symbols/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "akshayaedu.com"
Ubuntu/Debian:
sudo apt-get install php-zip
Redhat/CentOS:
sudo yum install php-zip
If you are having multiple versions of PHP and want to link Zip extension with a specific version of PHP, then below is the command:
sudo apt-get install php7.0-zip
or
sudo yum install php7.0-zip
Restart Apache/Nginx Web Server:
sudo systemctl restart nginx
or
sudo systemctl restart apache2
or
/etc/init.d/nginx restart
or
/etc/init.d/apache restart
If you are using PHP-FPM, then you need to restart this service also.
sudo systemctl restart php-fpm
or
sudo systemctl restart php-fpm
or
/etc/init.d/php-fpm restart
or
/etc/init.d/php-fpm restart
Is your PHP saying that it cannot find the ZipArchive class? Then, this post will show you how to enable the ZipArchive module.
You should see the following error:
PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found
Also, below is an example of the code you may be using:
$zip = new ZipArchive();
$x = $zip->open($target_path);
if ($x === true) {
$zip->extractTo($target_dir . $name[0]);
$zip->close();
}
What does this error mean?
This error means that PHP could not find the ZipArchive class. Therefore, PHP needs to have the zip extension installed for the ZipArchive Class to be present.
You can check whether ZipArchive is installed by using a PHP info file.
See an example below:
Your PHP info file should return something like this:
Next, scroll down until you find the heading “Configuration” and then continue until you see the following:
You will know that the ZipArchive class is not enabled if you cannot see: “Zip” configuration “enabled”.
You can also check whether the Zip module is enabled using the CLI.
Show compiled in modules using: php -m.
[email protected]:/var/www/html# php -m
[PHP Modules]
Core
ctype
date
dom
zip
zlib
[Zend Modules]
As the PHP module list can get quite large, consider using the grep command to filter your list:
Or you can use “php -m” to show the PHP information in the CLI.
How to enable ZipArchive on Windows
Windows users have it easy! You do not need to do anything if you use PHP 5.3 or newer. So, don’t trust that the code written and evaluated on Windows will work on Linux.
As of PHP 5.3, this extension is built-in. Before, Windows users needed to enable php_zip.dll inside of php.ini to use these functions.
https://www.php.net/manual/en/zip.installation.php
Before you enable ZipArchive
You can enable Zip support during the installation of PHP and after the fact. This post will focus on an after-the-fact ZipArchive installation on Linux. Please read the installing Zip instruction from the PHP manual for more information.
Before you continue, note the following helpful command to get your current version of PHP:
[email protected]:/var/www/html# php -v
PHP 7.4.2 (cli) (built: Feb 1 2020 19:39:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Note the version in the example above being: 7.4.2. We will, therefore, need to install the Zip module for PHP version 7.4. Please remember to change the version number to match yours if the command requires it!
Also, make sure that your packages are up to date using the “apt-get update” command:
[email protected]:/var/www/html# apt-get update
Hit:1 http://security.debian.org/debian-security buster/updates InRelease
Hit:2 http://deb.debian.org/debian buster InRelease
Hit:3 http://deb.debian.org/debian buster-updates InRelease
Reading package lists... Done
Lastly, you may need to determine the location of the loaded php.ini file. Please note that the CLI uses its version.
Use the following command to help you:
[email protected]:/var/www/html# php --ini
Configuration File (php.ini) Path: /usr/local/etc/php
Loaded Configuration File: /usr/local/etc/php/php.ini
Scan for additional .ini files in: /usr/local/etc/php/conf.d
Additional .ini files parsed: /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
/usr/local/etc/php/conf.d/docker-php-ext-sodium.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini
How to enable ZipArchive on Docker
First, run the following command to install Zip and compile PHP correctly to run it.
apt-get install -y libzip-dev zip && docker-php-ext-install zip
Below you will see how to restart Apache or NGINX. Once you install, you have finished.
Note that you will get an “E: Package ‘php-XXX’ has no installation candidate” error if you try to install any of Debian‘s PHP packages. This error is the default intended behavior of the official PHP Docker image.
You can see an example of this behavior below:
[email protected]:/var/www/html# apt-get install php-zip
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package php-zip is a virtual package provided by:
php7.3-zip 7.3.14-1~deb10u1 [Not candidate version]
php7.3-zip 7.3.11-1~deb10u1 [Not candidate version]
E: Package 'php-zip' has no installation candidate
You can also get the following error if you specify a specific version.
[email protected]:/var/www/html# apt-get install php7.0-zip
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.0-zip
E: Couldn't find any package by glob 'php7.0-zip'
E: Couldn't find any package by regex 'php7.0-zip'
How to enable ZipArchive on Linux on Ubuntu
The install PHP Zip command:
sudo apt-get install -y php-zip
The output will result in something like this:
[email protected]:/home/user# sudo apt-get install php-zip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libzip5 php-common php7.3-common php7.3-zip
The following NEW packages will be installed:
libzip5 php-common php-zip php7.3-common php7.3-zip
0 to upgrade, 5 to newly install, 0 to remove and 48 not to upgrade.
1 not fully installed or removed.
Need to get 1,003 kB of archives.
After this operation, 7,443 kB of additional disk space will be used.
Please note that you may need to specify the PHP version if you upgraded to a recent version of PHP.
Don’t forget to restart your web server!
The configuration file (php.ini) is only read when PHP or the webserver starts. Equally, the php.ini file is only read at invocation for the CGI and CLI versions.
You can restart Apache using:
Likewise, you can restart NGINX using:
Wrapping up
It is easy to get your website zipping files and avoid a fatal error. I hope that you now know how to enable ZipArchive for PHP. No one likes seeing a “Fatal error: Class’ ZipArchive’ not found in”.
You may also be interested in
About the Authors
Anto’s editorial team loves the cloud as much as you! Each member of Anto’s editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.
Support the Cause
Support Anto Online and buy us a coffee. Anything is possible with coffee and code.
Buy me a coffee
One of my client wanted to write tutorials containing lots of mathematical equations and formulas. By default, WordPress editor supports few symbols, but using those is not that simple. Also, the client was more comfortable in writing tutorials in Microsoft Word, as it supports plenty of mathematical symbols. I know WordPress supports remote publishing via XML-RPC, but if the Word document contains mathematical symbols then it may not appear as it is on a WordPress post. So how about uploading the Word document as an attachment and embed its content in a post? Well, it’s possible using docxpresso plugin and I’ll write a separate article on how to use the same. In this tutorial I will show how to fix ‘Uncaught Error Class ZipArchive not found’ error while using docxpresso WordPress plugin.
How to fix Uncaught Error Class ZipArchive not found
As we all know, Microsoft Word is such a powerful tool to create mathematical equations and my client was very comfortable in using it. So providing any other solution might make his writing difficult.
At first, I thought copying mathematical equations from Word and pasting it into WordPress will work. Unfortunately, it didn’t. So, I just thought of a work around by uploading the Word document to WordPress and publish it as a post? Fortunately, a WordPress plugin called docxpresso came to rescue. This plugin will allow you to publish content that has been generated with your favorite office suite (MS, Libre or Open Office) preserving all of its structure, design and format. As told earlier, I’m not going to explain how to use docxpresso plugin, as I’ll reserve it for another tutorial. Here I’ll tell you how to solve “Uncaught Error Class ZipArchive not found” error after installing docxpresso in WordPress.
Issue: Activating docxpresso plugin broke the website. Ah! my bad! After debugging, I could find the exact issue in error_log
.
PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found in /public_html/wp-content/plugins/docxpresso/CreateDocument.inc:87 Stack trace: #0 /public_html/wp-content/plugins/docxpresso/plugin.php(67): DocxpressoCreateDocument->__construct(Array) #1 /public_html/wp-includes/shortcodes.php(319): docxpresso_call(Array, '', 'docxpresso') #2 [internal function]: do_shortcode_tag(Array) #3 /public_html/wp-includes/shortcodes.php(197): preg_replace_callback('/\[(\[?)(docxpr...', 'do_shortcode_ta...', '[docxpresso fil...') #4 /public_html/wp-includes/class-wp-hook.php(286): do_shortcode('[docxpresso fil...') #5 /public_html/wp-includes/plugin.php(203): WP_Hook->apply_filters('[docxpresso fil...', Array) #6 /public_html/wp-includes/post-template.php(240): apply_filters('the_content', '[docxpresso fil" while reading response header from upstream, client: 14.139.1.29, server: akshayaedu.com, request: "GET /testing-mathematical-symbols/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "akshayaedu.com"
Error: Class ‘ZipArchive’ not found
After googling, found a hint that the zip extension
has to be installed for zipArchive
class to be present.
If you are on a shared hosting, then you may request the hosting provider to install PHP zip extension on your server.
Install PHP Zip Extension
If your webserver is on Linux, then you can install PHP Zip extension using the below command:
Ubuntu/Debian:
sudo apt-get install php-zip
Redhat/CentOS:
sudo yum install php-zip
If you are having multiple versions of PHP and want to link Zip extension with a specific version of PHP, then below is the command:
sudo apt-get install php7.0-zip or sudo yum install php7.0-zip
Once done, restart the web server.
Restart Apache/Nginx Web Server:
sudo systemctl restart nginx or sudo systemctl restart apache2 or /etc/init.d/nginx restart or /etc/init.d/apache restart
Restart PHP-FPM:
If you are using PHP-FPM, then you need to restart this service also.
sudo systemctl restart php-fpm or sudo systemctl restart php-fpm or /etc/init.d/php-fpm restart or /etc/init.d/php-fpm restart
That’s it! Now I activated docxpresso WordPress plugin and everything worked fine.
Ramya Santhosh
is a Web Designer and content creator. A freelance writer on latest trends in technology, gadget reviews, How to’s and many more.