用PHP安装RAR软件包 [英] Installing RAR package with PHP

查看:73
本文介绍了用PHP安装RAR软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装rar软件包.我检查了php.net的安装文档,它只是说要执行 pecl -v install 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

我做到了,并重新启动了服务器,但它仍然无法正常工作.我对Linux的东西不是很熟悉,所以也许我做错了什么?

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也不会显示有关RAR软件包的任何信息.

Phpinfo also display nothing about RAR package.

我正在尝试执行此脚本,我在php.net文档上找到了它,因此它应该可以工作:

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();

推荐答案

回答这个已有4年历史的问题,仅仅是因为我遇到了同样的问题,而且我对PHP/Apache/Pecl堆栈还很陌生:

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

基本上,我遵循了指南.但是,我已经安装了2个版本的PHP,并且必须进行一些调整才能使其正常工作(同时,更新有关PHP版本自2018年起的工作方式的说明):

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

pecl -v安装rar

RAR扩展已安装在/usr/lib/php/20131226

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

  1. 检查了我的扩展目录在哪里:

  1. Checked where were my extensions directory:

php -i | grep extension
extension_dir => /usr/lib/php/20160303 => /usr/lib/php/20160303

  • /etc/php/5.6/apache2/php.ini

    extension=/usr/lib/php/20131226/rar.so
    

  • 然后,像往常一样重新启动apache服务器,一切正常!

  • Then, restarted apache server as usual and everything worked fine!

    sudo service apache2 restart 
    

  • 这篇关于用PHP安装RAR软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆