User:FlyingBullets/SearXNG

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.


SearXNG (or "searching") is a free internet metasearch engine which aggregates results from various search services and databases. SearXNG allows users to specify which search engines they want to include in their search results, group engines in categories, specify engine timeouts, and more. Users can use SearXNG by using someone else's instance or by self-hosting an instance themselves.

TODO: For customization:

  • using someone else's instance uses cookies
  • self-hosted should edit the settings.yml file

Installation

Emerge

We will use Git (dev-vcs/git) to download the SearXNG repository. If Git isn't installed, do so now.

root #emerge --ask dev-vcs/git


Make the SearXNG user

The SearXNG server will be running as user searxng; technically, we can name this user anything. We also specify several other options:

  • --shell /bin/bash Specify the shell this user uses.
  • --system Make a system account; this user is intended to be ran by the machine and not by a human (this user will be given numeric identifiers that represent system identifiers).
  • -m Make a home directory for this user.
  • --home-dir /usr/local/searxng Specify the home directory.
  • --comment 'Privacy-respecting metasearch engine' Add a comment to describe this user.
root #useradd --shell /bin/bash --system -m --home-dir /usr/local/searxng --comment 'Privacy-respecting metasearch engine' searxng


Most of the following commands will need to be ran by the searxng user; switch to this user now.

root #sudo -u searxng -i


Clone the Git repository

As the user searxng, clone the Git repository for SearXNG into the home directory (/usr/local/searxng).

searxng $git clone "https://github.com/searxng/searxng" /usr/local/searxng/searxng-src


Make the virtual environment

SearXNG uses several Python packages installed with pip. We need to make a virtual environment for pip to install packages into so that they don't conflict with system packages.

searxng $python -m venv /usr/local/searxng/searx-pyenv


At this point, the virtual environment is installed, but it must be activated to use it; this is done by sourcing the file /usr/local/searxng/searx-pyenv/bin/activate. It can get tiresome to source this file every time we need to manage SearXNG; to fix this, we can append a command to searxng's .bashrc file so that it gets sourced every time we switch to this user.

searxng $echo ". /usr/local/searxng/searx-pyenv/bin/activate" >>/usr/local/searxng/.bashrc


We can go ahead and source the file that activates the virtual environment. The result of this command should prefix "(searx-pyenv)" to PS1 (the prompt).

searxng $. /usr/local/searxng/searx-pyenv/bin/activate


Update the boilerplate

With the user and virtual environment set up, we can now use pip to install packages.

(searx-pyenv) searxng $pip install -U pip setuptools wheel pyyaml


Install SearXNG into the virtual environment

Now we switch to SearXNG's working tree and install SearXNG.

(searx-pyenv) searxng $cd /usr/local/searxng/searxng-src
(searx-pyenv) searxng $pip install -e .


(Optional) Install uWSGI

SearXNG can be started manually by logging in as searxng and running a python script. To have SearXNG start at boot, we can set up a python web server; in this case, we will be using uWSGI.

Note
There is a difference between uWSGI and uwsgi (all lowercase)[1]:
  • uWSGI is the name of the application.
  • uwsgi is the name of the protocol.

Install uWSGI (www-servers/uwsgi).

root #emerge --ask www-servers/uwsgi

If we try to run rc-service uwsgi start, OpenRC will tell us that we should make a symlink to the uWSGI service we want. So, we do exactly that.

root #ln -s /etc/init.d/uwsgi{,.searxng}

Don't forget to add the service to the default run level.

root #rc-update add uwsgi.searxng default


Note
The default configuration file for a uWSGI service is located at /etc/conf.d/uwsgi. We can make a copy of this file to /etc/conf.d/uwsgi.searxng and customize it to our needs.

TODO: when computer finishes compiling, add final instructions for uWSGI here.

TODO: move default file note to "Configuration" section.

Configuration

Environment variables

  • VAR1
  • VAR2

Files

  • /etc/global_file_example - Global (system wide) configuration file.
  • ~/.local_file_example - Local (per user) configuration file.

Service

OpenRC

runit

systemd

Usage

Important
Any changes made to the preferences web browser will not be kept TODO: add more here


Manual

SearXNG can be started manually by running the Python executable as user searxng.

user $sudo -u searxng -i
(searx-pyenv) searxng $python searx/webapp.py


Now, open any web browser from Links to Firefox and visit http://127.0.0.1:8888. We should be met with the SearXNG search engine.


uWSGI

If we are using uWSGI to start SearXNG, there is nothing we need to do if uWSGI is set up correctly and running. If everything is working, open any web browser from Links to Firefox and visit http://127.0.0.1:8888. We should be met with the SearXNG search engine.

Caveats

Tips

Troubleshooting

Issue 1

When X happens, Y is how to fix it.

Removal

Unmerge

root #emerge --ask --depclean --verbose category/package

See also

External resources

References