前言

膜拜过许多大佬使用Typecho搭的博客,觉得他们的主题特别好看,特来体验一下。

Typecho官方的介绍:

轻量高效:仅仅 7 张数据表,加上不足 400KB 的代码,就实现了完整的插件与模板机制。超低的 CPU 和内存使用率,足以发挥主机的最高性能。

先进稳定:原生支持 Markdown 排版语法,易读更易写。支持 BAE/GAE/SAE 等各类云主机,即使面对突如其来的高访问量,也能轻松应对。

简洁友好:精心打磨过的操作界面,依然是你熟悉的面孔,更多了一份成熟与贴心。每一个像素的剪裁,都只为离完美更进一步。

配置环境

Typecho是一个动态博客框架,需要Web服务器+数据库+PHP。

系统环境是CentOS 7.3,Web服务器选用的是Nginx,数据库选用的是MySQL

首先安装Nginx

1
rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm

启动Nginx

1
systemctl start nginx

在浏览器访问服务器公网IP,出现Welcome to nginx!则Nginx启动成功!

将Nginx设为开机自启

1
systemctl enable nginx

Nginx Web服务器安装完成!

下面安装MySQL

1
2
3
4
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server

改变文件属主和属组

1
chown mysql:mysql -R /var/lib/mysql

初始化并启动mysql

1
2
mysqld --initialize
service mysqld start

如果用root用户初始化可能会报安全启动错误,忽视即可

修改mysql管理员密码并登陆mysql

1
2
mysqladmin -u root password "your-password"
mysql -u root -p

输入密码登陆,出现“mysql>”则登陆成功!

最后安装PHP

安装EPEL(Extra Packages for Enterprise Linux)源

1
yum install epel-release

安装WEBTATIC 源

1
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装PHP及其扩展

1
2
3
4
yum install php71w php71w-fpm \
php71w-cli php71w-common php71w-devel php71w-gd \
php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath \
php71w-pecl-redis

启动PHP

1
systemctl start php-fpm

查看PHP是否开启

1
ps -ef | grep php

开启控制台会输出PHP进程相关信息

将PHP设置为开机自启

1
systemctl enable php-fpm

至此,Typecho所需环境都配置完成!

搭建站点

创建站点目录

1
mkdir -p /var/www/example.com

其中的”example.com”为使用的域名,请将所有的”example.com”替换为自己使用的域名,也可使用IP

下载并解压Typecho

1
2
3
4
cd /var/www/example.com
yum install wget
wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
tar -xzvf 1.1-17.10.30-release.tar.gz

将解压出的文件移动至站点根目录

1
mv /var/www/example.com/build/* /var/www/example.com

删除多余文件

1
rmdir build && rm 1.1-17.10.30-release.tar.gz

站点文件下载完成!接下来只需配置Nginx和PHP即可!

创建站点的Nginx配置文件

1
2
cd /etc/nginx/conf.d
vim example.com.conf

内容为

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
server { 
listen 80;
server_name example.com;

location / {
root /var/www/example.com;
index index.html index.htm index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

同样,需要将所有的”example.com”改为自己使用的域名

完成后按下ESC键后输入”:wq”回车保存退出文件

重启Nginx

1
systemctl reload nginx

修改PHP配置文件

1
vim /etc/php-fpm.d/www.conf

按下i键编辑,将其中的”user = apache”改为

1
user = nginx

将其中的”group = apache”改为

1
group = nginx

完成后按下ESC键后输入”:wq”回车保存退出文件

重启PHP

1
systemctl restart php-fpm

最后,为Typecho创建数据库

1
mysql -u root -p

输入数据库root用户密码登录数据库

1
create database typecho;

创建完成后退出数据库

1
exit;

浏览器输入域名即可访问Typecho安装界面,按照提示填写相关内容即可!

最后

Typecho是国人开发的非常简洁的博客框架,操作习惯非常符合国人,也有很多漂亮的主题,但是开发者已经三年没有更新了,所以使用Typecho作为长期博客框架要仔细考虑考虑。