跳转至

Ubuntu安装静态网站评论系统HashOver

当网站是生成的静态页面,需要添加评论,否则总显得少了点什么。

HashOver官网:http://tildehash.com/?page=hashover,项目主页:https://github.com/jacobwb/hashover-next。HashOver只要PHP就可以运行,所以请准备一个LNMP的环境

配置nginx文件

vi /etc/nginx/sites-enabled/comments.zimoapps.com.conf
打开后粘贴入:
server {
    server_name comments.zimoapps.com;
    listen 80;
    listen [::]:80;
    return 301 https://$server_name$request_uri;
}
server {
    server_name comments.zimoapps.com;
    root /var/www/comments.zimoapps.com;
    listen 443      ssl http2;
    listen [::]:443 ssl http2;
    index index.php index.html index.htm;
    ssl_certificate     /etc/letsencrypt/live/zimoapps.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/zimoapps.com/privkey.pem;
    location ~\.php$ {
        root /var/www/comments.zimoapps.com; 
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}
nginx -s reload使配置生效

安装-HashOver

从hashover的GitHub项目地址下载其最新的文件,并完成解压:

cd ~/
wget https://github.com/jacobwb/hashover-next/archive/master.zip
unzip master.zip
上述操作完成后,将在~/下得到hashover-next-master目录。
hashover-next-master复制到网站目录,并重命名为comments.zimoapps.com
cp -r hashover-next-master /var/www/
mv /var/www/hashover-next-master  /var/www/comments.zimoapps.com

修改权限及所有者:

chmod -R 777 /var/www/comments.zimoapps.com
chown -R www-data:www-data /var/www/comments.zimoapps.com

配置-HashOver

将工作目录切换到/var/www/comments.zimoapps.com:

cd /var/www/comments.zimoapps.com/
hashover的配置主要涉及backend/classes/secrets.phpbackend/classes/sensitivesettings.php两个文件。

secrets.php

打开backend/classes/secrets.php

vi backend/classes/secrets.php
看到的是secrets.php里面的默认配置,相应的配置项都有详细的说明: 必须配置的项有:
protected $notificationEmail = 'example@example.com'; // Admin e-mail address to send notifications to
protected $noreplyEmail = 'noreply@example.com';      // E-mail address to use in notifications to normal users
protected $encryptionKey = '8CharKey';                // Unique encryption key (case-sensitive)                          
protected $adminName = 'admin';                       // Login name to gain admin rights (case-sensitive)
protected $adminPassword = 'passwd';                  // Login password to gain admin rights (case-sensitive)
选配项:
protected $databaseType = 'sqlite';        // Type of database, sqlite or mysql
protected $databaseName = 'hashover';      // Database name
protected $databaseHost = 'localhost';     // SQL database host name
protected $databasePort = '3306';          // SQL database port number
protected $databaseUser = 'root';          // SQL database login user
protected $databasePassword = 'password';  // SQL database login password
protected $databaseCharset = 'utf8';       // SQL database character set

           // OPTIONAL SMTP MAILER SETUP
protected $smtpHost = 'smtp.gmail.com';    // SMTP server host name
protected $smtpPort = 465;                 // SMTP server port number
protected $smtpCrypto = 'ssl';             // SMTP server encryption method
protected $smtpAuth = true;                // SMTP server requires login authentication
protected $smtpUser = 'user';              // SMTP server user
protected $smtpPassword = 'password';      // SMTP server password
根据描述,对响应配置项进行修改。我的配置如下,可以参考:
<?php namespace HashOver;
class Secrets
{
        protected $notificationEmail = 'zimo@zimoapps.com';
        protected $noreplyEmail = 'service@zimoapps.com';
        protected $encryptionKey = 'zimohash';
        protected $adminName = 'zimo';
        protected $adminPassword = '442412613yin';
        protected $databaseType = 'mysql';
        protected $databaseName = 'commentszimoappscom';
        protected $databaseHost = 'localhost';
        protected $databasePort = '3306';
        protected $databaseUser = 'root';
        protected $databasePassword = '442412613db';
        protected $databaseCharset = 'utf8';
        protected $smtpHost = 'smtp.mxhichina.com';
        protected $smtpPort = 465;
        protected $smtpCrypto = 'ssl';
        protected $smtpAuth = true;
        protected $smtpUser = 'service@zimoapps.com';
        protected $smtpPassword = '442412613Yin';
}

注意

如果上面的配置中,设置了$databaseType = 'mysql';,使用mysql来存储评论,需要手动创建数据库名称($databaseName = 'commentszimoappscom';): 登录数据:

mysql -uroot -p
然后新建数据库commentszimoappscom
create database commentszimoappscom;
quit;

sensitivesettings.php

打开backend/classes/sensitivesettings.php

backend/classes/sensitivesettings.php

secrets.php一样,sensitivesettings.php的配置项也全部有详细说明:

// Primary settings
public $dataFormat       = 'xml';           // Format comments will be stored in; options: xml, json, sql
public $defaultName      = 'Anonymous';     // Default name to use when one isn't given
public $allowsLogin      = true;            // Whether users can login and logout (when false form cookies are still set
public $usesModeration   = false;           // Whether comments must be approved before they appear to other visitor
public $pendsUserEdits   = false;           // Whether comments need to be approved again when edited

// E-mail setting
public $mailer           = 'sendmail';      // How to send notification e-mails, either 'sendmail' or 'smtp'
public $mailType         = 'text';          // What format to send e-mails in, either 'text' or 'html'

// Behavior setting
public $usesAutoLogin    = true;            // Whether a user's first comment automatically logs them in
public $imageFormat      = 'png';           // Format for icons and other images (use 'svg' for HDPI)

// Date and Time setting
public $datePattern      = 'MMMM d, YYYY';  // Date format pattern (see: http://userguide.icu-project.org/formatparse/datetime
public $timePattern      = 'h:mm a';        // Time format pattern, use 'HH:mm' for 24-hour time

// Technical setting
public $loginMethod      = 'DefaultLogin';  // Login method class for handling user login information
public $requiresLogin    = false;           // Whether user must be logged in to comment (only for restrictive login methods
public $secureCookies    = false;           // Whether cookies set over secure HTTPS will only be transmitted over HTTP
public $storesIpAddress  = false;           // Whether to store users' IP addresses
public $spamDatabase     = 'remote';        // Whether to use a remote or local spam database
public $spamCheckModes   = 'php';           // Perform IP spam check in 'json' or 'php' mode, or 'both'
public $enabledApi       = array ('all');   // An array of enabled API. 'all' = fully-enabled, empty array = fully disable
public $latestMax        = 10;              // Maximum number of comments to save as latest comments
public $unlinksFiles     = false;           // Whether user deleted files are actually unlinked from the filesyste
public $localMetadata    = false;           // Whether metadata should be collected while running on a local server

// Whether multiple website support is enabled
public $supportsMultisites = false;

// External domains allowed to remotely load HashOver scripts
public $allowedDomains = array (
        // '*.example.com',
        // '*.example.org',
        // '*.example.net'
);

// Types of images allowed to be embedded in comments
public $imageTypes = array (
        'jpeg',
        'jpg',
        'png',
        'gif'
);

我的配置如下:

<?php namespace HashOver;
class SensitiveSettings extends SafeSettings
{
    // Primary settings
    public $dataFormat              = 'sql';          
    public $defaultName             = 'Anonymous';         
    public $allowsLogin             = true;           
    public $usesModeration          = false;          
    public $pendsUserEdits          = false;               

    // E-mail settings
    public $mailer                  = 'smtp';         
    public $mailType                = 'html';              

    // Behavior settings
    public $usesAutoLogin           = true;           
    public $imageFormat             = 'png';               

    // Date and Time settings
    public $datePattern             = 'MMMM d, YYYY'; 
    public $timePattern             = 'h:mm a';            

    // Technical settings
    public $loginMethod             = 'DefaultLogin';      
    public $requiresLogin           = false;          
    public $secureCookies           = false;          
    public $storesIpAddress         = false;               
    public $spamDatabase            = 'remote';            
    public $spamCheckModes          = 'php';               
    public $enabledApi              = array ('all');  
    public $latestMax               = 10;                  
    public $unlinksFiles            = false;          
    public $localMetadata           = false;          

    public $supportsMultisites = false;

    public $allowedDomains = array (
            '*.zimoapps.com',
            '*.zimohan.com'
    );

    public $imageTypes = array (
            'jpeg',
            'jpg',
            'png',
            'gif'
    );
}

注意

如果准备在多个网站(域名)上使用,在设置$allowedDomains时,域名之间使用逗号隔开。

使用-HashOver

访问https://comments.zimoapps.com/hashover/admin输入账号密码后登录后台。