Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing RAR package with PHP

Tags:

php

apache

rar

I'm trying to install the rar package. I checked php.net's installation docs and it just said to execute pecl -v install rar

I did it and rebooted server but its still not working. I'm not very familiar with the Linux stuff so maybe did I do something wrong?

Phpinfo also display nothing about RAR package.

I'm trying to execute this script, I found it on php.net docs so it should be working:

$rar_arch = RarArchive::open('dl/test.rar');
if ($rar_arch === FALSE)
die("Could not open RAR archive.");

$rar_entries = $rar_arch->getEntries();
if ($rar_entries === FALSE)
die("Could retrieve entries.");

echo "Found " . count($rar_entries) . " entries.\n";

foreach ($rar_entries as $e) {
echo $e;
echo "\n";
}
$rar_arch->close();
like image 559
John Smith Avatar asked Nov 26 '25 05:11

John Smith


1 Answers

Answering this 4 year old question just because I had the same problem and I'm fairly new to the PHP/Apache/Pecl stack:

Basically, I followed this guide. However, I have 2 versions of PHP installed and had to make some tweaks to make it work (also, update instructions to how PHP versions work as of 2018):

  1. sudo apt-get install php5.6-dev

  2. pecl -v install rar

RAR extension was installed on /usr/lib/php/20131226

  1. Checked where were my extensions directory:

    php -i | grep extension
    extension_dir => /usr/lib/php/20160303 => /usr/lib/php/20160303
    
  2. Added a line on /etc/php/5.6/apache2/php.ini

    extension=/usr/lib/php/20131226/rar.so
    
  3. Then, restarted apache server as usual and everything worked fine!

    sudo service apache2 restart 
    
like image 185
adrield Avatar answered Nov 27 '25 20:11

adrield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!