Php zip extension включить

How to enable PHP zip extension in cPanel

Are you looking to enable PHP zip extension in cPanel? We can help you.

PHP websites using zip files needs zip extensions for data processing.

At Bobcares, we receive requests to enable PHP zip extensions as a part of our Server Management Services.

Today, let’s see how our Support Engineers enable PHP zip extension in cPanel.

Why do we need the PHP zip extension?

Website owners always look for ways to optimize website files. Zipping is one way to reduce file size.

A zip archive file format supports lossless data compression, thereby making it suitable for sending and storing data.

If websites use a zip file format, it needs a zip extension to process it. That is, zip extension allows the users to read and write into the zip files.

Now, let’s see how our Support Engineers enable PHP zip extensions in cPanel.

How to enable the PHP zip extension in cPanel?

1. Firstly, we log into cPanel and click on the PHP PEAR Packages available under the SOFTWARE section. The icon appears as in the image.

Enable PHP zip extension cPanel

Common errors while enabling PHP Zip extension

Now, let’s see a few common errors our customers reported to us while enabling the PHP zip extension.

1. Missing library

Recently, one of our customers approached us with the below error message

PHP ZipArchive Library is missing or disabled

Our Support Engineers checked the current PHP version using the command,

He used CentOS 6 with Apache and PHP 7.0. The PHP 7 provides a php7.0-zip package. We installed it using the command,

We used the below command to check the libraries,

yum list installed | grep -i php

Lastly, we ran the below command to restart Apache,

Finally, this fixed the error.

2. Installation command error

The PHP zip extensions can be enabled through commands as well. So, few customers try to install it via commands itself. But mistakes in the command lead to errors.

Читайте также:  What is input next in java

Here is an example where the customer experienced an error due to incorrect command.

The customer received the error Class ZipExtension not found . He was using CentOS 7 and PHP 7.0.27.

Our Support Engineers checked the command he used. The command was,

yum install php70-php-pecl-zip

The actual package was php-pecl-zip.x86_64. So we installed it using the command,

yum install php70-php-pecl-zip.x86_64

And then, we enabled it by running the command,

echo "extension=zip.so" >> /etc/php.d/zip.ini

This fixed the error and the PHP extension was enabled.

[Need assistance in enabling the PHP extension? – We’ll help you.]

Conclusion

In short, PHP websites using zip files require zip extensions for data processing. Today, we saw how our Support Engineers enabled PHP zip extension in cPanel.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

Источник

How to enable PHP zip extension in your web hosting

Posted on Jul 28, 2022

PHP zip extension is used to read and write compressed zip files. This extension is usually required to make PHP-based applications able to interact with zip files.

Sometimes, you may see the “PHP zip is not installed or has been disabled message” in WordPress.

Here are the steps to enable the PHP zip extension in your hosting from cPanel:

  1. Log into your cPanel account
  2. Go to the Select PHP Version menu
  3. Click the Extensions tab
  4. Check the zip extension to enable it

The tutorial below will show you how to do these steps in detail:

Enable PHP zip in your hosting

Login to your cPanel account, then look for the Select PHP Version menu under the Software tab:

cPanel Select PHP Version

Next, click on the Extensions tab and see the zip extension under the Z entries as shown below:

enable PHP zip in extensions tab

Click the checkbox beside the zip extension to enable it.

What if you don’t see the zip extension?

If you don’t see the zip extension, then you may need to install it first.

Get back to your cPanel home page, then find the PHP PEAR Packages menu.

It’s also located under the Software tab as shown below:

PHP PEAR Packages menu

On the PEAR Packages page, use the search menu to look for the “zip” extension.

You should see the Archive_Zip extension shown in the search result like this:

PHP Archive_Zip module

Click on Install to have the extension installed on your hosting.

Finally, go back to the Select PHP Version menu and check the Extensions tab. You should see the zip extension already checked on this page.

And that’s how you enable PHP zip in your hosting provider. Good work! 👍

Take your skills to the next level ⚡️

I’m sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I’ll send new stuff straight into your inbox!

Читайте также:  Массив свойство объекта javascript

About

Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials.
Learn statistics, JavaScript and other programming languages using clear examples written for people.

Type the keyword below and hit enter

Источник

How to Enable PHP Zip Extension in cPanel (3 Easy Steps)

Enable PHP Zip Extension

Technoracle

Website speed is really very important in terms of site performance, usability, SEO ranking. To optimize your website, you need PHP zip to be installed on the server, to hold compressed PHP files. Sometimes, you may also encounter an error that PHP zip-archive library is missing or disabled. In this tutorial, I will share a step-by-step guide to enable PHP zip extension in cPanel. So, let’s get started.

Step 1: Log in to your cPanel

Login to cPanel and go to PHP PEAR Package. Type Zip in the search bar.

Step 2: Install PHP Zip Extension

Now, you will find Archive_Zip. Click on install to continue.

Step 3: Change the PHP Version and Enable PHP Zip Extension

Change to PHP version to anything that is not native and click on “Set as Current”

Conclusion

In this tutorial, you have learned to enable PHP zip extension in Cpanel. Hurray, you have successfully enabled PHP zip extension. If you have any doubt, feel free to comment below. Also, you can join our elite Facebook group to get direct help from me. If you like this article, please share this article on your social media handle.

Rajesh Shivam is a seasoned professional with expertise in AWS and Linux System Administration. With over 10 years of freelancing experience, he brings a wealth of knowledge to the table. Rajesh has a strong passion for technology and stays connected with the latest happenings in the field. His dedication and expertise make him a trusted resource for all things tech-related.

Источник

PHP Zip Extension

PHP Zip Extension

  1. Install ZIP Extensions in Ubuntu
  2. Use the ZipArchive() Class to Create a Zip File in PHP
  3. Use the ZipArchive() Class to Create a Zip File in PHP
  4. How to Use PHP Zip Extension to Get Information of All the Member Files of a ZIP

Zip extension is one of the most important items in file handling. If you want to compress files or move multiple files through one file, ZIP will be required for this.

We need to install libzip to perform operations involving the ZIP extension for other platforms.

Install ZIP Extensions in Ubuntu

ZIP is already included in windows PHP. We will try to install this library for Ubuntu .

Run the following commands in Ubuntu to install the libzip library.

$ sudo apt-get update $ sudo apt-get install -y $ sudo apt-get install libzip-dev 
Setting up libzip-dev:amd64 (1.7.3-1+ubuntu20.04.1+deb.sury.org+2) . Processing triggers for man-db (2.9.1-1) . Processing triggers for libc-bin (2.31-0ubuntu9.2) . 

The next step is to install a PHP extension for ZIP .

$ sudo apt install php7.4-zip 

Once it is successfully installed, you can use it in PHP.

Читайте также:  JQuery Hello World Example

Use the ZipArchive() Class to Create a Zip File in PHP

ZipArchive() is the class used to perform ZIP operations in PHP. Using the ZipArchive() class, create a Zip file.

php $create_zip = new ZipArchive(); $file_name = "./New.zip";  if ($create_zip->open($file_name, ZipArchive::CREATE)!==TRUE)   exit("cannot open the zip file $file_name>\n"); > $current_dir=getcwd(); //Create files to add to the zip  $create_zip->addFromString("file1 ". time().".txt" , "#1 This is This is the test file number one.\n"); $create_zip->addFromString("file2 ". time().".txt", "#2 This is This is the test file number one.\n"); //add files to the zip  $create_zip->addFile($current_dir . "/too.php","/testfromfile.php"); echo "Number of files added: " . $create_zip->numFiles; echo "
"
;
echo "Failed to add:" . $create_zip->status ; $create_zip->close(); ?>

The code above creates two text files with some content and adds them into a zip file.

Use the ZipArchive() Class to Create a Zip File in PHP

Let’s extract the zip file created in the first code using the ZipArchive() class of PHP.

php $extract_zip = new ZipArchive; $open_zip = $extract_zip->open('New.zip'); if ($open_zip === TRUE)   $extract_to = getcwd();  $extract_zip->extractTo($extract_to); //extract to the current working directory.  echo "Number of Files to be Extracted:" . $extract_zip->numFiles . "
"
;
$extract_zip->close(); echo 'Files Successfully Extracted!'; > else echo 'Cannot Extract!'; > ?>

The above code will extract the New.zip file created in the first example.

How to Use PHP Zip Extension to Get Information of All the Member Files of a ZIP

The PHP ZIP extension can get the information of all the files inside a ZIP .

php $zip_file = zip_open("New.zip"); if ($zip_file)   while ($zip_members = zip_read($zip_file))   echo "Name of the file: " . zip_entry_name($zip_members) . "
"
;
echo "Original Size of the File: " . zip_entry_filesize($zip_members) . "
"
;
echo "Compressed Size of the File: " . zip_entry_compressedsize($zip_members) . "
"
;
echo "Method of Compression: " . zip_entry_compressionmethod($zip_members) . "
"
;
if (zip_entry_open($zip_file, $zip_members, "r")) echo "Content of the file:
"
;
$buf = zip_entry_read($zip_members, zip_entry_filesize($zip_members)); echo "$buf
"
;
zip_entry_close($zip_members); > echo "
"
;
> zip_close($zip_file); > ?>

The code above uses built-in ZIP functions to get the information of files inside a ZIP .

Name of the file: file1 1644842283.txt Original Size of the File: 45 Compressed Size of the File: 39 Method of Compression: deflated Content of the file: #1 This is test file number one.  Name of the file: file2 1644842283.txt Original Size of the File: 45 Compressed Size of the File: 39 Method of Compression: deflated Content of the file: #2 This is test file number two. 

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

Related Article — PHP Zip

Источник

Оцените статью