本文将介绍如何搭建基于Typecho的我的网站,以及分享一些遇到问题的解决方案。php
Typecho是一个由国人开发的轻量级CMS,和WordPress同样,能够快速创建我的博客网站。So Why Typecho? WordPress有无数的优势,可是选择Typecho的理由只需一个:简单,简洁,轻量级。 Typecho几乎是专门为我的博客打造的,所有代码不足400KB,也不像WordPress同样对主机性能有必定的要求。界面和控制台都是极简风,很是清爽,很容易上手。对MarkDown支持很是友好,不须要额外的插件。 html
Typecho的推荐环境是LNMP(Linux, Nginx, MySQL, PHP),跟WordPress很是类似,能够共用。 由于本人以前写过在Ubuntu上搭建WordPress环境的步骤,为避免重复造轮,Linux,MySQL,PHP7的部分能够参考这里。mysql
会获得以下输出 > ● nginx.service - A high performance web server and a reverse proxy server > Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) > Active: active (running) since Thu 2019-12-05 10:19:16 CST; 4h 29min ago > Process: 80264 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS) > Process: 80384 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) > Process: 80380 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)nginx
Nginx默认安装在 /etc/nginx/目录下,在此目录下找到默认的配置文件sites-enabled/default(不一样的Nginx版本或者操做系统文件会有区别),把index.php加到index标签下,同时将PHP对应的location打开web
index **index.php** index.html; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; }
要确保已经安装了php-fpm,不然Nginx没法正常给php作转发。若是尚未安装,运行以下命令安装 > sudo apt install php-fpm php-mysqlsql
直接从官网下载最新的版本,解压到Nginx目录 > cd /usr/share/nginx > > sudo wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz > > tar -zxvf 1.1-17.10.30-release.tar.gz > > cp ./build/* ./html/浏览器
不要忘了修改一下Nginx发布目录的权限 > cd /usr/share/nginx/html > > chmod -R 755 * > > chown {owner}/{group} *php7
若是是Ubuntu,owner和group都是www-data,若是是CentOS则事nginx,能够经过如下命令查看用户 > ps -ef | grep nginxwordpress
如今浏览器打开 {ip}:80(nginx默认80端口)应该能够看到Typecho的欢迎页面了 typecho
按照向导一步一步走下来,能够看到简洁清爽的博客界面
若是打开页面报502 bad gateway,是由于xml解析不兼容形成的,安装php7.0-xml便可解决,Ubuntu > sudo apt-get install php7.0-xml
CentOS下 > yum install php7.0-xml
若是打开任何Typecho子页面都报404 not found,须要在nginx的配置文件添加以下配置
location / { 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; } }
在php的location下添加参数fastcgi_split_path_info ^(.+.php)(/.+)$;,参考以下
server { listen 80 default_server; listen [::]:80 default_server; root /usr/share/nginx/typecho; index index.php index.html; server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. 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; } try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_split_path_info ^(.+\.php)(/.+)$; # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } }
Typecho有插件支持从WordPress转移文章,可是建议安装老版本的Typecho环境,并且对WordPress的版本有要求,至少博主在WordPress5和Typecho1.1下没有迁移成功。因此建议不要迁移哈哈哈。
Typecho环境的搭建与WordPress很是类似,若是你是想要一个纯粹极简博文网站,并习惯MarkDown写文,那就感受上手Typecho吧,你值得拥有。