CentOS 8部署Typecho——记录自己的blog!

一、环境

1.硬件

  • 选择一台具有公网ip的主机(新用户薅各厂商的云服务器折扣),个人使用2核4G的轻量级应用服务器
  • 系统:Linux CentOS 8.2

2.软件

  • Typecho稳定版17.10.30——http://typecho.org/download
  • Typecho运行环境:

    • PHP 5.1以上
    • MySQL、PostgreSQL、SQLite等数据库并在PHP中安装相关扩展
  • Nginx

二、安装

1.Typecho

将下载的压缩包上传至服务器相应目录,解压

2.安装PHP、sqlite3

$yum install nginx php php-fpm sqlite3 php-sqlite3 php-curl php-mbstring

启动nginx

$systemctl enable nginx
$systemctl start nginx

访问服务器ip地址,看nginx是否成功

3.配置nginx

在/etc/nginx/路径下找到nginx.conf,打开并配置server

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        # root         /usr/share/nginx/html;
        root         /data/typecho//1.1-17.10.30-release/build;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #location / {
        #    try_files $uri $uri/ =404;
        #}
        
        # PHP页面访问
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/run/php-fpm/www.sock;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

设置typecho目录权限

$chmod 777 -R /data/typecho/

访问ip/install.php界面即可进入typecho的安装过程

三、配置域名、DNS和SSL

1.域名

域名需要在所购买云服务器的云服务商处进行域名的购买和备案。购买可以在任意云服务商购买,但一定要在服务器资源所在的云服务商处进行备案,例如:域名edicaran.cafe最初购买于腾讯云,在腾讯云进行备案并绑定腾讯云资源的IP地址;当服务器已迁移至华为云,需要在华为云处进行重新备案并绑定华为云资源的IP地址。

2.DNS解析

根据云服务商的相关文档进行DNS解析配置,域名要与ip进行绑定

3.SSL

由于通过http请求访问存在安全风险,一般采用https的方式进行安全可靠的访问操作。https需要向云服务商购买或申请SSL证书,免费证书有效期仅一年,需要申请后将证书安装至服务器。
具体配置操作参见另一篇博文:强制https安全访问的nginx配置记录