I need to extract rar file for my custom import extension.

i have used shell_exec() and exec("unzip/path/images.rar", $result, $returnval); but not working.

Any one knows how to extract rar file using SSH+php


2 Answers 2


For Debian or Ubuntu Linux use apt-get

For Fedora Linux / CentOS / RHEL use yum

Install unrar on server

sudo apt-get install unrar

for zip file install unzip

sudo apt-get install unzip

then try

exec("unrar unzip/path/images.rar");

for zip

exec("unzip path/images.zip");
  • hi can you please give me suggestion for zip also ? @gopal patel Mar 28, 2017 at 6:55
  • find updated answer @denishvachhani Mar 28, 2017 at 6:57
  • can you please specify how to use target to destination path in this ? Mar 28, 2017 at 6:59
  • 1
    @GopalPatel perfect just replace apt-get to yum in centos Mar 28, 2017 at 6:59
  • 1
    @MurtuzaZabuawala yeah updated sirji ;) Mar 28, 2017 at 7:02

Did you try running the rar x archive.rar command inside shell_exec().

shell_exec('rar x path/to/rar/file/filename.rar');

Make sure that path of the rar file is correct.

If the file is in the same folder where your php file is then you can give the filename without giving any path.

First, check if rar is installed in your Linux system.

if not installed, then you can run the following command -

sudo apt-get install rar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.