本教程适用于以下操作系统版本

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 16.04 (Xenial Xerus)

本页内容

  • 前提条件
  • 开始准备
  • 安装 Apache、PHP 和 MariaDB 服务器。
  • 创建 MariaDB 数据库
  • 下载 Chevereto
  • 为 Chevereto 配置 Apache
  • 访问 Chevereto Web 界面
  • 使用 Let's Encrypt SSL 保护 Chevereto
  • 结论

Chevereto 是一款免费开源的图片托管与分享软件,可让你在 Web 上搭建自己的图片托管服务器。它是一款自托管、多用途、多用户且功能齐全的图片托管解决方案,可让你创建响应式的图片托管网站。它提供众多功能,包括多语言、批量图片导入、社交媒体集成、多服务器等。

在本文中,我们将向你展示如何在 Ubuntu 22.04 上安装 Chevereto 图片托管解决方案。

前提条件

  • 一台运行 Ubuntu 22.04 的服务器。
  • 服务器上已配置 root 密码。

开始准备

首先,建议将所有系统软件包更新并升级到最新版本。你可以运行以下命令来更新它们:

apt update -y
apt upgrade -y

所有软件包升级完成后,运行以下命令安装其他所需的依赖项:

apt install apt-transport-https ca-certificates curl software-properties-common -y

所有依赖项安装完成后,即可进入下一步。

安装 Apache、PHP 和 MariaDB 服务器。

开始之前,你需要在服务器上安装 LAMP 服务器。

首先,使用以下命令安装 Apache 和 MariaDB 服务器:

apt install apache2 mariadb-server

接下来,使用以下命令将 PHP 仓库添加到 APT:

add-apt-repository ppa:ondrej/php -y

接下来,使用以下命令安装 PHP 7.4 版本及其他所需的扩展:

apt install php7.4 libapache2-mod-php7.4 php7.4-cli php7.4-fpm php7.4-json php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath -y

所有软件包安装完成后,即可进入下一步。

创建 MariaDB 数据库

首先,运行以下脚本来加固 MariaDB 安装并设置 root 密码:

mysql_secure_installation

如下所示回答所有问题:

Enter current password for root (enter for none): Press ENTER
Set root password? [Y/n]: Y
New password: Set-your-new-password
Re-enter new password: Set-your-new-password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

接下来,使用以下命令登录 MariaDB:

mysql -u root -p

登录后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE chevereto;
MariaDB [(none)]> CREATE USER 'chevereto'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令为 Chevereto 数据库授予所有权限:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON chevereto.* TO 'chevereto'@'localhost';

接下来,刷新权限以使更改生效:

MariaDB [(none)]> FLUSH PRIVILEGES;

最后,使用以下命令退出 MariaDB shell:

MariaDB [(none)]> EXIT;

下载 Chevereto

首先,使用以下命令在 Apache Web 根目录中为 Chevereto 创建一个目录:

mkdir -p /var/www/html/chevereto/

接下来,进入 Chevereto 目录,并使用以下命令下载最新版本的 Chevereto:

cd /var/www/html/chevereto
wget https://github.com/rodber/chevereto-free/releases/download/1.6.0/1.6.0.zip

下载完成后,使用以下命令解压下载的文件:

unzip 1.6.0.zip

接下来,为 Chevereto 目录设置适当的权限和所有权:

chown -R www-data:www-data /var/www/html/chevereto/
chmod -R 775 /var/www/html/chevereto/

为 Chevereto 配置 Apache

接下来,使用以下命令为 Chevereto 创建 Apache 虚拟主机配置文件:

nano /etc/apache2/sites-available/chevereto.conf

添加以下配置:

<VirtualHost *:80>

ServerAdmin 
[email protected]

ServerName chevereto.example.com
DocumentRoot /var/www/html/chevereto

ErrorLog ${APACHE_LOG_DIR}/chevereto.example.com_error.log
CustomLog ${APACHE_LOG_DIR}/chevereto.example.com_access.log combined

<Directory /var/www/html/chevereto/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

</VirtualHost>

完成后保存并关闭文件。接下来,使用以下命令启用 Chevereto 虚拟主机:

a2ensite chevereto.conf

接下来,使用以下命令启用 Apache rewrite 和 SSL 模块:

a2enmod rewrite ssl

最后,重启 Apache 服务以使更改生效:

systemctl restart apache2

你也可以使用以下命令查看 Apache 的状态:

systemctl status apache2

你应该会看到以下输出:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-28 07:22:12 UTC; 9s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 87027 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 87032 (apache2)
      Tasks: 6 (limit: 2242)
     Memory: 14.1M
        CPU: 111ms
     CGroup: /system.slice/apache2.service
             ??87032 /usr/sbin/apache2 -k start
             ??87033 /usr/sbin/apache2 -k start
             ??87034 /usr/sbin/apache2 -k start
             ??87035 /usr/sbin/apache2 -k start
             ??87036 /usr/sbin/apache2 -k start
             ??87037 /usr/sbin/apache2 -k start

Aug 28 07:22:12 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

访问 Chevereto Web 界面

现在,打开 Web 浏览器,使用 URL http://chevereto.example.com 访问 Chevereto Web 界面。你将被重定向到数据库配置页面:

使用 Chevereto 搭建图片托管网站的完整安装教程

填写你的数据库信息,然后点击 Continue 按钮。你应该会看到以下页面:

使用 Chevereto 搭建图片托管网站的完整安装教程

使用 Chevereto 搭建图片托管网站的完整安装教程

现在,填写管理员用户名、密码和网站模式,然后点击 Install Chevereto 按钮。安装完成后,你应该会看到以下页面:

使用 Chevereto 搭建图片托管网站的完整安装教程

点击 admin dashboard 按钮。你应该会看到 Chevereto 登录页面:

使用 Chevereto 搭建图片托管网站的完整安装教程

填写管理员用户名、密码,然后点击 = > 按钮。你应该会在接下来的页面中看到 Chevereto dashboard:

使用 Chevereto 搭建图片托管网站的完整安装教程

使用 Let's Encrypt SSL 保护 Chevereto

此外,建议使用 Let's Encrypt SSL 来保护你的网站。首先,你需要在服务器上安装 Certbot 客户端。你可以使用以下命令安装它:

apt-get install python3-certbot-apache -y

Certbot 安装完成后,运行以下命令以使用 Let's Encrypt SSL 保护你的网站:

certbot --apache -d chevereto.example.com

系统将要求你提供邮箱并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 
[email protected]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for chevereto.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/chevereto-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/chevereto-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/chevereto-le-ssl.conf
Next, select whether or not to redirect HTTP traffic to HTTPS as shown below:

请选择是否将 HTTP 流量重定向到 HTTPS,从而移除 HTTP 访问。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

输入 2 并按 Enter 键,为你的网站安装 Let's Encrypt SSL:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/chevereto.conf to ssl vhost in /etc/apache2/sites-available/chevereto-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://chevereto.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=chevereto.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/chevereto.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/chevereto.example.com/privkey.pem
   Your cert will expire on 2022-11-29. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

结论

恭喜!你已在 Ubuntu 22.04 上成功安装 Chevereto 图片托管服务器。现在你可以将图片上传到服务器,并从 Web 上的任何位置访问它。如有任何问题,欢迎随时向我提问。