本文將介紹如何搭建基於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吧,你值得擁有。