美文网首页
sphinx(五)php执行sphinx更新索引rotate命令

sphinx(五)php执行sphinx更新索引rotate命令

作者: camellias__ | 来源:发表于2021-02-08 16:42 被阅读0次

我将sphinx全文检索应用到我的博客中。

我这里使用thinkphp5.0框架,其实这玩意跟我用啥框架还真没有啥关系。

将sphinxapi.php文件放到你能引用到的地方就好。参照前几篇中的php的demo代码就可以了。

当然,上边说的只是PHP中sphinx的使用。

执行到这里,我发现了一个小问题:

我该如何维护sphinx的索引,说实话,我博客中的数据不多,说维护,其实就是每次生成全部索引就可以了。

这样的话,我就可以在更新博客文章的时候,使用PHP执行更新索引的命令就可以了。

但是,在使用PHP执行更新索引的命令的时候遇到了几个小问题,这里记录一下:

1:确定服务器中web用户

我的服务器中web用户是apache

<?php
exec(“whoami”,$res,$return);
var_dump( $return);

2:确定sphinx安装目录下的文件apache用户有执行权限

1.png 2.png

上图中的文件需要有执行权限。

3:执行更新索引命令

<?php
exec('sudo -s /usr/local/sphinxforchinese/bin/indexer -c /usr/local/sphinxforchinese/etc/sphinx.conf  --all --rotate ', $res, $return_val);
var_dump($res);
var_dump($return_val);

(1):报错:

sudo: no tty present and no askpass program specified

解决方法:

编辑sudoers文件

vim /etc/sudoers

添加免密码:

用户名 ALL = NOPASSWD: ALL

如:jenkins ALL = NOPASSWD: ALL

(2):再次执行报错:

This account is currently not available # 该账户不可用

解决方法:

vim /etc/passwd

apache:x:48:48:Apache:/usr/share/httpd:/ sbin /nologin

改成

apache:x:48:48:Apache:/usr/share/httpd:/bin/bash

保存退出。

再次执行,索引生成成功。

有好的建议,请在下方输入你的评论。

欢迎访问个人博客
https://guanchao.site

相关文章

网友评论

      本文标题:sphinx(五)php执行sphinx更新索引rotate命令

      本文链接:https://www.haomeiwen.com/subject/ynqfxltx.html