Debian/Ubuntu下搭建轻量级 typecho 博客

安装配置PHP

1.1、php7.1的安装方法:
Sury官方原始源:HTTPS://packages.sury.org/php/ 
镜像源:HTTPS://mirror.xtom.com.hk/sury/php/

增加GPG:

wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg

部署apt-transport-https:

apt-get install apt-transport-https

增加sury软件源:

sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

更新软件源缓存:

apt-get update


安装php7.1:

apt install php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache -y

常用命令:
systemctl restart php7.1-fpm //重启php
systemctl start php7.1-fpm //启动php
systemctl stop php7.1-fpm //停止php
systemctl status php7.1-fpm //php状态

1.2、php7.0的安装方法:
Debian自带的是7.0,如需安装可以直接运行下面命令:

apt install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache -y

安装完成后,我们先需要修改一下 PHP 的配置文件,需要把 /etc/php/7.1/fpm/php.ini 中的 cgi.fix_pathinfo 设置项去掉注释,并设为0

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.1/fpm/php.ini

这个设置项会允许服务器在找不到用户指定文件的情况下去执行一个路径相近文件,非常不安全,强烈建议关闭掉

重启php服务使设置生效

systemctl restart php7.0-fpm

安装配置MySQL

安装MariaDB:

apt install mariadb-server

配置MariaDB:

mysql_secure_installation

创建typecho数据库:

create database typecho char set utf8;

创建MariaDB用户,设置用户名为'typecho',密码为'123456':

CREATE USER 'typecho'@'localhost' IDENTIFIED BY '123456';

允许用户'typecho'访问'typecho'数据库:

GRANT ALL PRIVILEGES ON typecho.* TO 'typecho'@'localhost';

刷新表:

FLUSH PRIVILEGES;

设置自启动
systemctl enable php7.1-fpm
systemctl enable mariadb

安装Caddy

先安装curl

apt-get update -y && apt-get install curl -y

安装Caddy及Caddy service文件:

ulimit -n 51200 \
&& apt-get install -y libcap2-bin \
&& curl https://getcaddy.com | bash -s personal dns,http.cache,http.filter,http.git,http.ipfilter,http.realip && chown root:root /usr/local/bin/caddy && chmod 755 /usr/local/bin/caddy && setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy \
&& curl -s https://raw.githubusercontent.com/mholt/caddy/master/dist/init/linux-systemd/caddy.service -o /etc/systemd/system/caddy.service && chmod 644 /etc/systemd/system/caddy.service \
&& mkdir /etc/caddy && chown -R root:www-data /etc/caddy && touch /etc/caddy/Caddyfile && mkdir /etc/ssl/caddy && chown -R www-data:www-data /etc/ssl/caddy && chmod 0770 /etc/ssl/caddy \
&& mkdir /var/log/caddy && chown -R www-data:www-data /var/log/caddy

配置Caddy,下面为一条命令,直接复制就可以了,也可以根据自己的情况更改:

echo '
 https://www.aaa.com, http://www.aaa.com, http://aaa.com {
 redir https://aaa.com{uri}
}
aaa.com {        
  root /var/www/typecho
  log / /var/log/caddy/aaa_com.log "{remote} - {user} [{when}] {when_unix} \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\""
  tls [email protected] {
    max_certs 10
  }
  gzip
  header / Strict-Transport-Security "max-age=31536000"
  fastcgi / /run/php/php7.1-fpm.sock php
  rewrite {
    if {path} not_match ^\/admin
    to {path} {path}/ /index.php?{query}
  }
  realip {
    from 0.0.0.0/0
  }
}' > /etc/caddy/Caddyfile

重新载入配置文件

systemctl daemon-reload

运行Caddy

systemctl start caddy

常用命令:
systemctl start caddy
systemctl stop caddy
systemctl restart caddy
systemctl status caddy
systemctl enable caddy

安装typecho

下载typecho

wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz

解压文件

tar zxvf 1.1-17.10.30-release.tar.gz //解压后的文件夹为build

创建目录

mkdir -p /var/www/typecho

移动目录

mv build/* /var/www/typecho

设置权限

chown -R www-data:www-data /var/www/
chmod -R 755 /var/www/

创建phpinfo

echo '<?php phpinfo(); ?>' > /var/www/typecho/info.php

测试配置是否正确

https://aaa.com/info.php

配置站点

https://aaa.com/

在显示的页面中使用前面创建的数据库用户名和密码,点下一步即可搭建完成。(不可以用root,如果使用root会提示无法创建数据库。)

最后修改:2019 年 09 月 15 日 10 : 30 PM

发表评论