I need to reload SPHINX SEARCH via PHP. In terminal I do this:
sudo indexer --all --rotate
And it works fine, but now I need to do this via php.
f.e. shell_exec('sudo indexer --all --rotate');
And it don't work. If i try to do it with www-data user I get:
Sphinx 2.2.9-id64-release (rel22-r5006) Copyright (c) 2001-2015, Andrew Aksyonoff Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'... skipping non-plain index 'rt'... indexing index 'test1'... WARNING: attribute 'id' not found - IGNORING collected 49433 docs, 45.1 MB sorted 4.8 Mhits, 100.0% done total 49433 docs, 45067658 bytes total 5.540 sec, 8133618 bytes/sec, 8921.45 docs/sec total 49607 reads, 0.042 sec, 1.9 kb/call avg, 0.0 msec/call avg total 424 writes, 0.106 sec, 373.8 kb/call avg, 0.2 msec/call avg WARNING: access denied to PID 16315. WARNING: indices NOT rotated.
WARNING: access denied to PID 16315. !!!
If I try to stop and start SPHINX with www-data i get:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.4502" (uid=33 pid=16887 comm="start sphinxsearch ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init ")
I'm playing with sh script shmod and chown and I get nothing.
You should just start searchd under the www-data user too. Avoids the need to use sudo. (although COULD allow sudo via, visudo)
So stop searchd. Change all indexes etc, logs and pids to be owned by www-data, and then
#stop current instance
searchd --stop
#change the owner of indexes and logs
chown www-data:www-data /path/to/index/folder/ -r
chown www-data:www-data /var/log/query.log
chown www-data:www-data /var/log/search.log
#start searchd up again
sudo -u www-data searchd
Then php in apache (running as www-data) can just call indexer as needed.
If you want to use upstart etc, will need to then modify its config file to run searchd as a specific user (can't just call service start/stop by running it as a specific user.