这主要是由于我我的博客的流量实在是不高,再加上国外的免费图床可能说被ban就被ban,国内图床又各类不稳定,这就致使我看到不少人的文章中的图片常常处于没法打开的状况。php
因此嘛,我就想本身搞一个,这样折腾一下,还能多学点知识html
因为本文是基于我本身的VPS环境配置的,在其余环境下步骤会有些许不一样,不确保彻底同样,因此我先写出我本身的环境,其余的状况应该大同小异吧mysql
咱们图床使用的是开源的Lychee,你们能够看到lychee仍是很是好看的nginx
首先要保证环境知足Lychee的条件,Lychee须要PHP5.5以上,而且安装了下列PHP拓展git
A web server (Apache, nginx, etc)github
A MySQL database (MariaDB also works)web
PHP 5.5 or later with the following extensions: session
, exif
, mbstring
, gd
, mysqli
, json
, zip
, and optionally, imagick
sql
运行php -m
查看下是否本身已经安装了这些拓展,没安装的话就用下面的命令安装数据库
sudo apt-get install php7.2-xx
复制代码
当咱们搞定了上面要求的这些环境以后,咱们继续json
咱们进入 /var/www
目录下,直接从github把Lychee拉下来
git clone --recurse-submodules https://github.com/LycheeOrg/Lychee.git
而后对相应的文件夹设置好权限
chmod -R 775 uploads/ data/
复制代码
接着咱们为新的页面设置Nginx Server Block,
进入/etc/nginx/sites-available/目录
vim /etc/nginx/sites-available/lychee
而后咱们将下面的内容复制粘贴,而后把root,server_name修改为咱们本身的地址
server {
listen 80;
root /var/www/Lychee;
index index.php index.html index.htm index.nginx-debian.html;
server_name lychee.mydomain;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param PHP_VALUE "max_execution_time=1800 post_max_size=1500M upload_max_filesize=32M max_input_time=1800 max_file_uploads=300";
}
location ~ /\.ht {
deny all;
}
}
复制代码
sudo ln -s /etc/nginx/sites-available/lychee /etc/nginx/sites-enabled/
因为我设置了Https,因此须要certbot来生成证书,这样咱们的这个站点就是https协议了
sudo certbot --nginx -d lychee.xxx.com
作完这些以后,重启Nginx
sudo systemctl reload nginx
相似Wordpress咱们须要新建一个lychee数据库
CREATE DATABASE lychee;
新增用户和密码
GRANT ALL PRIVILEGES ON lychee.* TO 'userName'@'localhost' IDENTIFIED BY 'user_passwd';
再接着咱们进入/etc/php/7.2/fpm/php.ini,将下面的属性修改成下面的值(Lychee的推荐)
max_execution_time = 200
post_max_size = 100M
upload_max_filesize = 20M
memory_limit = 256M
复制代码
重启PHP服务
sudo systemctl restart php7.2-fpm.service
复制代码
到如今,咱们就完成了全部须要的设置,用浏览器打开你设置的lychee的地址
若是成功了的话会提示你输入密码,输入你刚刚设置的MySQL用户名和密码
而后咱们能够尝试上传一个照片,咱们能够在Direct Link这里得到图片的连接
到这里咱们就能够将图片上传到咱们本身的图床,再也不须要担忧blog中的图片挂掉了。