原创文章,转载请注明出处
https://qiedd.com/

环境

Caddy2

PHP8.0

操作系统这里我使用了ArchLinux,如果你用的是其他操作系统,在安装Caddy和PHP时可以参考官方文档

安装PHP

ArchLinux

# 安装需要的依赖
pacman -S php php-fpm tar zip ffmpeg imagemagick php-imagick php-gd caddy unzip --needed

接下来需要修改php的配置文件

# 修改配置文件
vim /etc/php/php-fpm.d/www.conf

# 使用vim搜索功能
# 输入 /listen.owner 然后回车,将
listen.owner = http
listen.group = http
# 改成 caddy
listen.owner = caddy
listen.group = caddy

# 修改配置文件
vim /etc/php/php.ini

# 使用vim搜索功能
# 输入 extension=exif  然后回车,将
# ;extension=exif 和 ;extension=gd 前面的分号去掉
extension=exif
extension=gd

# 修改配置文件
vim /etc/php/conf.d/imagick.ini

# 取消注释
extension = imagick

然后就可以启动PHP了

# 设置开机启动
systemctl enable php-fpm

# 启动PHP
systemctl start php-fpm

H5ai安装

创建网站目录

# 创建
mkdir /www/example.com

H5ai官网下载最新的包,我这里用的0.30.0的

# 进入目录
cd /www/example

# 下载
wget https://release.larsjung.de/h5ai/h5ai-0.30.0.zip

# 解压
unzip h5ai-0.30.0.zip

# 删除压缩包
rm h5ai-0.30.0.zip 

安装Caddy

ArchLinux

# 安装caddy
pacman -S caddy

Caddyfile配置

将/etc/caddy/Caddyfile的默认文件注释掉只剩最后一行

# The Caddyfile is an easy way to configure your Caddy web server.
#
# https://caddyserver.com/docs/caddyfile
#
# The configuration below serves a welcome page over HTTP on port 80.
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
#
# https://caddyserver.com/docs/caddyfile/concepts#addresses

#{
        # Restrict the admin interface to a local unix file socket whose directory
        # is restricted to caddy:caddy. By default the TCP socket allows arbitrary
        # modification for any process and user that has access to the local
        # interface. If admin over TCP is turned on one should make sure
        # implications are well understood.
#       admin "unix//run/caddy/admin.socket"
#}

#http:// {
        # Set this path to your site's directory.
#       root * /usr/share/caddy

        # Enable the static file server.
#       file_server

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000

        # Refer to the directive documentation for more options.
        # https://caddyserver.com/docs/caddyfile/directives
#}

# Import additional caddy config files in /etc/caddy/conf.d/
import /etc/caddy/conf.d/*

然后在 /etc/caddy/conf.d 中新建一个conf,随意命名

# 示例 /etc/caddy/conf.d/h5ai

example.com {
        log {
                output file /var/log/caddy/h5ai.log
        }
        root * /www/example.com
        encode zstd gzip
        file_server 
        php_fastcgi unix//run/php-fpm/php-fpm.sock {
                index /_h5ai/public/index.php
        }
        @redirected {
                path /_h5ai/private/*
        }
        redir @redirected /
}

启动caddy

# 设置caddy开机启动
systemctl enable caddy

# 启动caddy
systemctl start caddy

H5ai配置

为了你的网站安全,请将权限更改至caddy

# 将网站权限更改为caddy
chown -R caddy /www/example.com
chgrp -R caddy /www/example.com

访问你的网站 example.com/_h5ai/public/index.php,没有密码,直接登录,看看有没有缺什么,装就是了

编辑 /www/example.com/_h5ai/private/conf/option.conf
以下为建议修改的地方

vim _h5ai/private/conf/options.json

设置密码

为 /_h5ai/public/index.php 设置密码,去http://md5hashing.net/hashing/sha512,算一个,然后替换到passhash

 Password hash.

    SHA512 hash of the info page password, the preset password is the empty string.
    Online hash generator: http://md5hashing.net/hashing/sha512
    */
    "passhash": "你的sha512",

多选下载

"download": {
    "enabled": true,
    "type": "php-tar",
    "packageName": null,
    "alwaysVisible": false
},

默认语言

    "l10n": {
        "enabled": true,
        "lang": "zh-cn",
        "useBrowserLang": true
    },

搜索功能

    "search": {
        "enabled": true,
        "advanced": true,
        "debounceTime": 300,
        "ignorecase": true
    },

自定义页头

找到 _h5ai/private/php/pages/index.php

修改 <title></title> 中的内容即可

分类: Linux

0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注

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