用 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#
进入网站根据提示一步一步安装即可。