Share&Joy

Ginger' Blog


  • 首页
  • 归档
  • 标签
  •   

© 2018 1-riverfish

Theme Typography by Makito

Proudly published with Hexo

搭建Chevereto图床

发布于 2018-05-15 LAMP Chevereto 

LAMP下Chevereto图床搭建

Markdown语法支持图片链接的插入,但是最近我经常用到的几个图床网站都出现了莫名的bug,俗话说自己动手丰衣足食,所以打算在闲置吃灰的云服务器上运行一个图床。简单在网上查了一下,部署相对简单且用户友好的图床有Chevereto,下面这张图片就是上传到这台服务器上图床的,速度蛮快的。

废话不多说,开始介绍Chevereto搭建步骤

环境

  • 运行Ubuntu 16.04的云服务器
  • 拥有sudo权限的非root用户

依赖

在开始前请安装下列软件包

1
2
3
4
5
6
# 更新系统
sudo apt update -y
sudo apt upgrade -y

# 安装下列需要的包
sudo apt install wget nano curl git -y

下边可以继续安装 LAMP server

Chevereto运行在 Apache web server, written in PHP languages 并且使用 MariaDB来存储他们的数据.所以你需要在你的系统上安装 LAMP(Apache,PHP,MariaDB)

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt-get install apache2 libapache2-mod-php7.0 mariadb-server mariadb-client php7.0 php7.0-mysql php7.0-dom php7.0-gd php7.0-mbstring php7.0-common bc php7.0-bcmath -y

# 安装好之后使用下列命令重启 Apache 和 MariaDB 并且设置开机启动
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql

# 下边你需要改变配置文件'php.ini'中的日期和时区设置
sudo nano /etc/php/7.0/cli/php.ini

# 根据你所在时区改变下列行,设置好之后关闭
date.timezone = Asia/Shanghai

配置数据库

默认数据库是不安全的,你可以通过下列命令使其安全

1
mysql_secure_installation

This command will set the root password, remove anonymous user, disallow root login remotely and remove test database.

按照下面的例子回答问题

1
2
3
4
5
Set root password? [Y/n] n
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

数据库安全配置好之后,你需要为Chevereto创建一个数据库和用户.首先,用下列命令登录数据库Shell

1
mysql -u root -p

输入你的密码,然后用下列命令为Chevereto创建一个数据库及用户

1
MariaDB [(none)]>CREATE DATABASE cheveretodb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

下面为Chevereto创建一个用户并赋予访问修改 Chevereto数据库的权限

1
MariaDB [(none)]>GRANT ALL PRIVILEGES ON cheveretodb.* TO 'chevereto'@'localhost' IDENTIFIED BY 'password';

用下面的命令更新

1
2
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>\q

下载安装Chevereto

1
2
3
4
5
6
7
8
9
10
11
12
# 下面开始从git仓库下载安装最新版本的 Chevereto
wget https://github.com/Chevereto/Chevereto-Free/archive/1.0.9.tar.gz

# 下载好之后解压
tar -xvzf 1.0.9.tar.gz

# 将解压好的目录移动到 Apache root文件夹下
sudo mv Chevereto-Free-1.0.9/* /var/www/html/chevereto

# 下面进入chevereto目录然后创建一个 settings.php 文件
cd /var/www/html/chevereto
sudo nano app/settings.php

在settings.php文件中写入以下内容

1
2
3
4
5
<?php
$config['db_name'] = 'cheveretodb';
$config['db_user'] = 'chevereto';
$config['db_pass'] = 'password';
$config['admin_password'] = 'password';

保存退出文件,然后给 Chevereto 文件夹正确的权限

1
2
sudo chown -R admin:admin /var/www/html/chevereto
sudo chmod -R 777 /var/www/html/chevereto

为Chevereto配置Apache

Next, you will need to create an Apache virtual host directive for Chevereto. You can do this by creating chevereto.conf file inside /etc/apache2/sites-available directory:

在文件中写入下列内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/chevereto/
ServerName 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>

保存关闭文件,然后使配置生效

1
2
sudo a2ensite chevereto
sudo systemctl restart apache2

配置防火墙

1
2
3
4
5
sudo ufw enable

sudo ufw allow 80

sudo ufw reload

访问网站链接

你的数据库信息如下

1
2
3
4
Database host : localhost
Database name : cheveretodb
Database user : chevereto
Database user password : password

提供你的admin user 如下

1
2
3
4
5
Admin username : admin
Admin email : admin@example.com
Admin password : password
From email address : no-reply@example.com
Incoming email address : admin@example.com

Next, click on the Install Chevereto button. You will be redirected to the Installation Completed page. Click on the admin dashboardbutton. You will be redirected to the Chevereto login page.

Now, enter your admin username and password and click on the sign in button. You will be redirected to the Chevereto dashboad.

真正有趣的部分

安装Curl

enable mod_rewrite

参考博客

Github

分享到 

 上一篇: 小试Python NetworkX绘图库 下一篇: 两只小爬虫 

© 2018 1-riverfish

Theme Typography by Makito

Proudly published with Hexo