用 Typeco 搭建個人博客 (LNMP 手動搭建)#
前期準備#
- Centos7 伺服器
- xshell 連接工具
1. 手動搭建 LNMP 環境#
雲伺服器 手動搭建 LNMP 環境(CentOS 7)- 最佳實踐 - 文檔中心 - 腾訊雲 (tencent.com)
Nginx#
yum install -y nginx
vi /etc/nginx/nginx.conf
server {
listen 80;
root /usr/share/nginx/myblog;
server_name zxcbz.top;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
#
location / {
index index.php index.html index.htm;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-e $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;
}
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .\.php(\ /.)*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
nginx -t
systemctl start nginx
systemctl enable nginx
Mariadb#
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
創建數據庫
create database typecho_mydb;
create user 'dbuser'@'localhost' identified by 'password';
grant all on typecho_mydb.* to 'dbuser'@'localhost';
flush privileges;
PHP72 及其相關組件#
-
依次執行以下命令,更新 yum 中 PHP 的軟件源。
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
-
執行以下命令,安裝 PHP 7.2 所需要的包。
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64 php72w-mbstring.x86_64
-
執行以下命令,啟動 PHP-FPM 服務。
systemctl start php-fpm
-
執行以下命令,設置 PHP-FPM 服務為開機自啟動。
systemctl enable php-fpm
2. 下載 Typecho#
sudo mkdir /var/www/mywebsite
cd /var/www/mywebsite/
sudo wget https://codeload.github.com/typecho/typecho/tar.gz/refs/tags/v1.2.0
sudo tar zxvf v1.2.0
cd /usr/share/nginx/
cp -ra /var/www/mywebsite/typecho-1.2.0 myblog #在/usr/share/nginx/下創建myblog目錄,並且把/var/www/mywebsite/typecho-1.2.0下的文件複製過來
3. 安裝 Typecho#
進入網站根據提示一步一步安裝即可。