Packing and Unpacking Files on a Server Using SSH or a PHP Script

On this page
  1. Method 1 – Using SSH
  2. Create a ZIP archive
  3. Extract a ZIP file in the same directory
  4. Extract a ZIP file to a specific folder
  5. Method 2 – Using a PHP Script
  6. Extracting ZIP files
  7. Creating ZIP archives
  8. Additional Notes
  9. Conclusion

When managing a hosting account, you may need to quickly compress or extract files directly on the server. This can significantly speed up deployments and reduce the need for FTP transfers. Below are two common methods: using SSH or using a PHP script.

Method 1 – Using SSH

After enabling SSH access and logging into your hosting account, you can manage archives directly from the command line.

Create a ZIP archive

To compress a folder into a ZIP file, use the following command:

zip -r archive_name.zip folder_name

This will create a compressed archive containing all files and subfolders inside the specified directory.

Extract a ZIP file in the same directory

To unpack an archive in its current location, use:

unzip archive_name.zip

Extract a ZIP file to a specific folder

If you want to extract files to a different directory, specify the destination path:

unzip archive_name.zip -d destination_folder

This is useful when deploying applications or restoring backups into specific locations.

Method 2 – Using a PHP Script

If SSH access is not available, you can use a PHP-based solution to manage ZIP archives directly from your browser.

Extracting ZIP files

For large archives containing hundreds or thousands of files, uploading them uncompressed via FTP can be inefficient. Instead, you can use a script such as Unzipper.

To use it:

  1. Upload unzipper.php to your domain’s root directory (for example, public_html)
  2. Upload the .zip archive you want to extract to the same directory
  3. Run the script via your browser

The script will extract all files directly on the server, saving time and bandwidth.

Creating ZIP archives

Some PHP tools also allow you to create ZIP archives directly on the server. This can be useful when backing up folders already stored on your hosting account.

Typically, you:

  • Select the folder you want to compress
  • Execute the archive creation function
  • Download or move the resulting .zip file as needed

Additional Notes

If you are working with FTP, you may also need a proper FTP client configuration to upload or download files efficiently.

For reference, see your hosting provider’s guide on connecting via FTP to manage files more easily.

Conclusion

Both SSH and PHP-based tools provide efficient ways to manage file archives on a server. SSH offers faster and more flexible control for advanced users, while PHP scripts are useful when SSH access is not available.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.