Wallabag – 自托管稍后阅读服务

wallabag is a self-hostable PHP application allowing you to not miss any content anymore. Click, save and read it when you can. It extracts content so that you can read it when you have time.

使用 PHP 开发,类似于 Pocket 的自托管服务,支持中文,支持从 Pocket 导入记录

下文将展示如何在 Debian 11 下无域名搭建 Wallabag

环境

  • Debian 11
    • PHP 7.4
      • Composer

参考

步骤

官方提供了 Docker 镜像,详细的使用方法可以查看 Docker Hub,下文选择原生方式安装

注意 Wallabag 的 makefile 无法在 root 用户下运行,习惯 root 一把梭的用户需要新建普通用户

运行环境准备

安装 PHP 7.4、MySQL

# PHP 及其组件
apt install php7.4 php-json php-gd php-mbstring php7.4-xml php7.4-fpm php7.4-intl php7.4-bcmath php7.4-xml php7.4-fpm php7.4-intl php7.4-bcmath php7.4-curl php7.4-tidy

# MySQL
wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
dpkg -i mysql-apt-config_0.8.22-1_all.deb
apt update
apt install mysql-community-server # 期间会要求设定数据库管理密码

PHP Composer 的安装

# 安装 PHP 后运行
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

# 将 Composer 移至系统目录
mv composer.phar /usr/local/bin/composer

获取并安装 Wallabag

获取 Wallabag 源码

git clone https://github.com/wallabag/wallabag.git

安装 Wallabag

cd wallabag
make

安装过程中需要完成一系列的配置,需要注意的配置项如下:

  • 如果使用了 MySQL 或者 PostgreSQL,需要指定正确的 database_port
  • 如果未来通过 IP 访问,在输入域名时输入 http://IP 即可

安装的最后一步是指定管理员账户,按照提示设置即可

配置网页服务器

注意:系统可能会自动安装 Apache,如果使用其他网页服务器需要先卸载 Apache

这里使用 nginx

首先将 Wallabag 移至 nginx 拥有权限的目录,由于这里的 nginx 通过包管理安装的,网页文件的默认存放目录是 /var/www

mv wallabag /var/www

将 Wallabag 的目录访问权限分配给 nginx 默认用户 www-data

chown -R www-data:www-data /var/www/wallabag

在 /etc/nginx/sites-available 下新建配置文件 wallabag,写入以下内容

server {
    listen 80;
    server_name _;
    root /var/www/wallabag/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    location ~ ^/app\.php(/|$) {
        # if, for some reason, you are still using PHP 5,
        # then replace /run/php/php7.0 by /var/run/php5
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/wallabag_error.log;
    access_log /var/log/nginx/wallabag_access.log;
}

新建软链接并启用配置

ln -s /etc/nginx/sites-available/wallabag /etc/nginx/sites-enabled
nginx -t
nginx -s reload

浏览器访问 IP 即可开始使用

效果

发表评论

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据