Linux php install zip

Ubuntu PHP ZIP Extension Install Commands Example

Today, I would like to show you how to install php zip extension in ubuntu. you will learn ubuntu php install zip extension. if you want to see an example of install php zip extension ubuntu 20.04 then you are in the right place. you will learn install php zip extension ubuntu. Let’s get started with ubuntu install php zip extension.

We can install php zip extension using php-zip library. i will give you following list of commands to install php zip extension in ubuntu 22.10, ubuntu 22.04, ubuntu 21.10, ubuntu 21.04, ubuntu 20.04, ubuntu 18.04 and ubuntu 16.04 server.

Install php-zip Extension:

You need to run both commands one by one:

sudo apt-get install php-zip

Solution for PHP 8.2

You need to run both command one by one:

sudo apt-get install php8.2-zip

Solution for PHP 8.1

You need to run both command one by one:

sudo apt-get install php8.1-zip

Solution for PHP 8.0

You need to run both command one by one:

sudo apt-get install php8.0-zip

Solution for PHP 7.4

You need to run both command one by one:

sudo apt-get install php7.4-zip

Solution for PHP 7.3

You need to run both command one by one:

sudo apt-get install php7.3-zip

Solution for PHP 7.2

You need to run both command one by one:

sudo apt-get install php7.2-zip

Restart Apache Server:

Now, restart apache2 server using following command:

sudo service apache2 restart

Check php-zip Extension Installed:

Here, we will run following command to check extension is installed or not:

Hardik Savani

I’m a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.

We are Recommending you

  • How to Increase upload_max_filesize in PHP Ubuntu?
  • How to Check Apache Access & Error Log Files in Ubuntu Server?
  • How to Whitelist/Allow IP Address in Apache Ubuntu?
  • How to Restrict/Block IP Address in Apache Ubuntu?
  • How to Change PHP Version in Ubuntu Server?
  • How to Install MySQL in Ubuntu Server?
  • How to Connect SSH using ppk File Ubuntu?
  • How to Connect to a Remote Server using SSH on Ubuntu?
  • How to Upgrade PHP Version from 7.4 to 8 in Ubuntu?
  • How to Import Database in Mysql using Command Line in Ubuntu?
  • How to Enable Apache mod_rewrite Module in Ubuntu?
  • How to Increase Upload File Size Limit PHP in Ubuntu?
  • How to Upgrade Node.js Version in Ubuntu?
  • How to Enable Rewrite Mode for Apache in Ubuntu?
Читайте также:  Linux mint какая оболочка лучше
  • How to Use Rsync with Specific Port in Linux?
  • Laravel Simple CMS Website using Asgardcms Example
  • Solved: Supported filenames: docker-compose.yml, docker-compose.yaml
  • How to Whitelist/Allow IP Address in Apache Ubuntu?
  • How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?
  • Connection for controluser as defined in your configuration failed — Ubuntu phpmyadmin Resolve?
  • How to Install Phpmyadmin in Ubuntu Server?
  • How to Install Composer using Command Line in Ubuntu?
  • PHP — How to Remove Blank Pages from PDF File?
  • How to Generate and Add SSH Key in Github?
  • How to Check Apache Access & Error Log Files in Ubuntu Server?

Источник

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.

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

Источник

How can I install ziparchive on php 7.4?

I am running Virtuamin on centos 7, I am unable to install ziparchive on php 7.4, but when I switch to php 7.2, it works. I need php 7.4 to work because it is faster and wordpress script need 7.3+ to work effectively.

4 Answers 4

sudo apt-get install php7.4-zip 

This works in ubuntu 18.04

Basically, it tells you to:

Add PPA for PHP 7.4 Add the ondrej/php which has PHP 7.4 package and other required PHP extensions.

sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update 

Then you can install the extension

sudo apt install php7.4-zip 

Or install all the commonly used ones:

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y 

I am on Debian 9, which does not ship with PHP7.4, but it can be installed if you add the repository from Sury.

sudo apt install ca-certificates apt-transport-https wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add - echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list 

After that, I ran this with success:

apt install php7.4-zip Reading package lists. Done Building dependency tree Reading state information. Done The following NEW packages will be installed: php7.4-zip 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 20.5 kB of archives. After this operation, 94.2 kB of additional disk space will be used. Get:1 https://packages.sury.org/php stretch/main amd64 php7.4-zip amd64 7.4.7-1+ 0~20200612.18+debian9~1.gbp671911 [20.5 kB] Fetched 20.5 kB in 0s (149 kB/s) Selecting previously unselected package php7.4-zip. (Reading database . 107553 files and directories currently installed.) Preparing to unpack . /php7.4-zip_7.4.7-1+0~20200612.18+debian9~1.gbp671911_amd 64.deb . Unpacking php7.4-zip (7.4.7-1+0~20200612.18+debian9~1.gbp671911) . Processing triggers for libapache2-mod-php7.4 (7.4.7-1+0~20200612.18+debian9~1.g bp671911) . Setting up php7.4-zip (7.4.7-1+0~20200612.18+debian9~1.gbp671911) . Creating config file /etc/php/7.4/mods-available/zip.ini with new version Processing triggers for php7.4-fpm (7.4.7-1+0~20200612.18+debian9~1.gbp671911) . .. NOTICE: Not enabling PHP 7.4 FPM by default. NOTICE: To enable PHP 7.4 FPM in Apache2 do: NOTICE: a2enmod proxy_fcgi setenvif NOTICE: a2enconf php7.4-fpm NOTICE: You are seeing this message because you have apache2 package installed. Processing triggers for libapache2-mod-php7.4 (7.4.7-1+0~20200612.18+debian9~1.g bp671911) . Processing triggers for php7.4-cgi (7.4.7-1+0~20200612.18+debian9~1.gbp671911) . .. Processing triggers for php7.4-cli (7.4.7-1+0~20200612.18+debian9~1.gbp671911) . .. 

Источник

How To Install php-zip on Ubuntu 20.04

In this tutorial we learn how to install php-zip on Ubuntu 20.04.

What is php-zip

This package provides a Zip module for PHP.

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

This package is a dependency package, which depends on Debian’s default PHP version (currently 7.4). Description-md5: 07531b708a43e2ff6f21e6733cf57aa2

There are three ways to install php-zip on Ubuntu 20.04. We can use apt-get , apt and aptitude . In the following sections we will describe each method. You can choose one of them.

Install php-zip Using apt-get

Update apt database with apt-get using the following command.

After updating apt database, We can install php-zip using apt-get by running the following command:

sudo apt-get -y install php-zip 

Install php-zip Using apt

Update apt database with apt using the following command.

After updating apt database, We can install php-zip using apt by running the following command:

sudo apt -y install php-zip 

Install php-zip Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

After updating apt database, We can install php-zip using aptitude by running the following command:

sudo aptitude -y install php-zip 

How To Uninstall php-zip on Ubuntu 20.04

To uninstall only the php-zip package we can use the following command:

sudo apt-get remove php-zip 

Uninstall php-zip And Its Dependencies

To uninstall php-zip and its dependencies that are no longer needed by Ubuntu 20.04, we can use the command below:

sudo apt-get -y autoremove php-zip 

Remove php-zip Configurations and Data

To remove php-zip configuration and data from Ubuntu 20.04 we can use the following command:

sudo apt-get -y purge php-zip 

Remove php-zip configuration, data, and all of its dependencies

We can use the following command to remove php-zip configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge php-zip 

References

Summary

In this tutorial we learn how to install php-zip package on Ubuntu 20.04 using different package management tools: apt, apt-get and aptitude.

Источник

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