0%

Chevereto 图床搭建教程

Chevereto 简介

Chevereto 是一款图床服务器软件,其社区版本可以让我们免费搭建自己的图床服务器。

Chevereto 安装

  1. 依赖

    • 云服务器 with LAMP
    • 域名
  2. 安装包

    Free Edition 页面下载最新版本安装包,下载地址:https://github.com/Chevereto/Chevereto-Free/releases/latest

  3. 配置

    apache配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/chevereto/
    ServerName images.example.com
    <Directory /var/www/html/chevereto/>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>
    ErrorLog /var/log/apache2/chevereto-error_log
    CustomLog /var/log/apache2/chevereto-access_log common
    </VirtualHost>

    https

    1
    2
    a2enmod ssl
    a2ensite default-ssl

    htaccess

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    # Disable server signature
    ServerSignature Off

    # Disable directory listing (-indexes), Multiviews (-MultiViews) and enable Follow system links (+FollowSymLinks)
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    php_value upload_max_filesize 90M
    <IfModule mod_rewrite.c>

    RewriteEngine On
    # If you have problems with the rewrite rules remove the "#" from the following RewriteBase line
    # You will also have to change the path to reflect the path to your Chevereto installation
    # If you are using alias is most likely that you will need this.
    RewriteBase /

    # 404 images
    # If you want to have your own fancy "image not found" image remove the "#" from RewriteCond and RewriteRule lines
    # Make sure to apply the correct paths to reflect your current installation
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule images/.+\.(gif|jpe?g|png|bmp) - [NC,L,R=404]
    #RewriteRule images/.+\.(gif|jpe?g|png|bmp) content/images/system/default/404.gif [NC,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !\.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpe?g|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC]
    RewriteRule . index.php [L]
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
    </IfModule>
  4. 修改文件上传大小上限

    /etc/nginx/nginx.conf

    1
    2
    3
    4
    5
    6
    7
    8
    ...
    http
    {
    ...
    client_max_body_size 40m;
    ...
    }
    ...

    /etc/php.ini

    1
    2
    3
    memory_limit = 32M
    upload_max_filesize = 24M
    post_max_size = 32M
  5. API Key与用户对应

    Chevereto 默认仅有 一个 API Key,通过该 Key 上传的图片不属于指定用户,通过以下修改可实现对应关系:

    复制app/routes/route.api.php到``app/routes/overrides`下

    1
    cp app/routes/route.api.php route.api-jonkimi.php

    修改route.api-jonkimi.php

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    $ diff route.api-jonkimi.php ../route.api.php
    37,39c37,38
    < if(!G\timing_safe_compare('your-api-key', $_REQUEST['key'])) {
    < throw new Exception(" Invalid API-J v1 key.", 100);
    < //throw new Exception($_REQUEST['key'], 100);
    ---
    > if(!G\timing_safe_compare(CHV\getSetting('api_v1_key'), $_REQUEST['key'])) {
    > throw new Exception("Invalid API v1 key.", 100);
    106,107c105
    < $uploaded_id = CHV\Image::uploadToWebsite($source, 'jonkimi');
    < //$uploaded_id = CHV\Image::uploadToWebsite($source);
    ---
    > $uploaded_id = CHV\Image::uploadToWebsite($source);
    153c151
    < };
    ---
    > };

安装问题

  1. cURL isn’t installed and allow_url_fopen is disabled. Chevereto needs one of these to perform HTTP requests to remote servers.

    1
    2
    apt-get install php5-curl
    service apache2 restart
  2. GD Library is not enabled in this server. GD is needed to perform image handling.

    1
    2
    apt-get install php5-gd
    service apache2 restart
  3. Apache mod_rewrite is not enabled in this server. This must be enabled to run Chevereto.

    1
    2
    sudo a2enmod rewrite
    service apache2 restart
  4. The requested URL /install was not found on this server

  5. sysctl: cannot stat /proc/sys/status: No such file or directory

  6. G: Sessions are not working on this server due to missing write permission on session save path (php.ini session.save_path).

    实际session目录配置为/etc/php-fpm.d/www.conf下的

    1
    php_value[session.save_path] = /var/lib/php/session

    修改该目录权限为同配置下的usergroup

参考