Lychee 相片管理系统搭建

针对内网使用环境搭建,不含域名、SSL 配置

环境

  • Debian 11
    • NMP
    • PHP Composer

参考

步骤

标准的 PHP Laravel 应用搭建过程

以下指令在 root 用户下执行

准备系统环境

安装 Nginx、MySQL、PHP 8.2

apt install nginx
rm /etc/nginx/sites-enabled/default

wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
php8.2 php8.2-{curl,bcmath,gd,mbstring,mysql,pgsql,xml,zip,fpm}
# 可能需要 apt remove apache2

wget https://dev.mysql.com/get/mysql-apt-config_0.8.23-1_all.deb
apt install mysql-apt-config_0.8.23-1_all.deb
apt update
apt insall mysql-community-server

Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer

配置数据库

mysql -u root -p

CREATE DATABASE lychee;
CREATE USER 'lychee'@'localhost' IDENTIFIED BY 'veryStrongPassword';
GRANT ALL PRIVILEGES ON lychee.* TO 'lychee'@'localhost' WITH GRANT OPTION;
exit

安装 Lychee

下载 Lychee 源码

cd /var/www
git clone https://github.com/LycheeOrg/Lychee.git

安装 PHP 依赖

cd Lychee
composer install --no-dev

创建环境变量文件

cp .env.example .env

按需编辑其中的 APP_URL、DB_CONNECTION、DB_HOST、DB_PORT、DB_DATABASE、DB_USERNAME 和 DB_PASSWORD,如下图黄框处

编辑完毕后执行指令生成绿框内的 APP_KEY

php artisan key:generate

数据库迁移

php artisan migrate

配置 Nginx

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

server {
    listen 80;
    server_name [IP];

    ##### Path to the Lychee public/ directory.
    root /var/www/Lychee/public/;
    index index.php;

    # If the request is not for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # Serve /index.php through PHP
    location = /index.php {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

        # Mitigate https://httpoxy.org/ vulnerabilities
        fastcgi_param HTTP_PROXY "";

        ######### Make sure this is the correct socket for your system
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        ######## You may need to replace $document_root with the absolute path to your public folder.
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "post_max_size=100M
            max_execution_time=200
            upload_max_filesize=30M
            memory_limit=300M";
        fastcgi_param PATH /usr/local/bin:/usr/bin:/bin;
        include fastcgi_params;
    }
    # Deny access to other .php files, rather than exposing their contents
    location ~ [^/]\.php(/|$) {
        return 403;
    }

    # [Optional] Lychee-specific logs
    error_log  /var/log/nginx/lychee.error.log;
    access_log /var/log/nginx/lychee.access.log;

    # [Optional] Remove trailing slashes from requests (prevents SEO duplicate content issues)
    rewrite ^/(.+)/$ /$1 permanent;
}

新建软链接

ln -s /etc/nginx/sites-available/lychee /etc/nginx/sites-enabled/

重载 Nginx

nginx -t
nginx -s reload

效果

发表回复

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

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