[英]Installing RAR package with PHP
I'm trying to install the rar package.我正在尝试安装 rar 包。 I checked php.net's installation docs and it just said to execute
pecl -v install rar
我检查了 php.net 的安装文档,它只是说执行
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?
我对 Linux 的东西不是很熟悉,所以也许我做错了什么?
Phpinfo also display nothing about RAR package. Phpinfo 也没有显示任何关于 RAR 包的信息。
I'm trying to execute this script, I found it on php.net docs so it should be working:我正在尝试执行这个脚本,我在 php.net docs 上找到了它,所以它应该可以工作:
$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();
Answering this 4 year old question just because I had the same problem and I'm fairly new to the PHP/Apache/Pecl stack:回答这个 4 年前的问题只是因为我遇到了同样的问题,而且我对 PHP/Apache/Pecl 堆栈还很陌生:
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):
但是,我安装了 2 个版本的 PHP,并且必须进行一些调整才能使其正常工作(此外,还更新了自 2018 年起 PHP 版本如何工作的说明):
sudo apt-get install php5.6-dev
pecl -v install rar
RAR extension was installed on /usr/lib/php/20131226
RAR 扩展安装在
/usr/lib/php/20131226
Checked where were my extensions directory:检查我的扩展目录在哪里:
php -i | grep extension extension_dir => /usr/lib/php/20160303 => /usr/lib/php/20160303
Added a line on /etc/php/5.6/apache2/php.ini
在
/etc/php/5.6/apache2/php.ini
添加一行
extension=/usr/lib/php/20131226/rar.so
Then, restarted apache server as usual and everything worked fine!然后,像往常一样重新启动 apache 服务器,一切正常!
sudo service apache2 restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.