Centos7安装Typecho博客

听说Typecho博客不错还是轻量的一个博客,搭建在腾讯云上,直到我学会Flask自己搭建为止了。

安装LNMP

1. 安装NGINX

  • 安装EPEL源

# yum install epel-release
# yum update -y

  • 安装NGINX

# yum install nginx wget

  • 启动nginx并添加开机自启服务

# systemctl start nginx
# systemctl enable nginx

  • 停止firewall

# systemctl stop firewalld
# systemctl disable firewalld

  • 测试一下

打开 ip 应该可以看到nginx欢迎界面的

2. 安装Mariadb

  • 安装mariadb服务端

# yum install mariadb-server mariadb

  • 启动并开机自启动

# systemctl start mariadb.service
# systemctl enable mariadb.service

  • 初始化mariadb数据库

# mysql_secure_installation 主要是里面root密码要记住,下面要用一下

  • 创建一个tyoecho数据库

不知道为什么安装的时候报错,所以手动创建一个数据库

# mysql -uroot -p输入密码登录mysql客户端
mysql> CREATE DATABASE typecho;

  • 重启数据库

# systemctl restart mariadb

3. 安装PHP

  • 安装PHP php-fpm

# yum install php php-devel php-fpm php-gd php-mbstring php-mysql

  • 启动php-fpm

# systemctl start php-fpm
# systemctl enable php-fpm

4. 配置Nginx并启用https(已经有了域名证书)

  • 配置php-fpm

# vim /etc/nginx/php-fpm.d/www.conf将apache改为nginx

  • 配置NGINX站点文件

# vim /etc/nginx/conf.d/typecho.conf


server
{
    listen 80;
    listen 443 ssl http2;
    server_name senlief.xyz www.senlief.xyz;
    index index.php index.html index.htm default.php default.htm default.html;
    root /var/www/html;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #301-START
        if ($host ~ '^typecho.wiki'){
            return 301 https://www.senlief.xyz$request_uri;
        }
    #301-END
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    <pem>;
    ssl_certificate_key    <key>;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

    #SSL-END
    if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }

    location ~ .*\.php(\/.*)*$ {
            include fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
        }

}
  • 重启nginx

# systemctl restart nginx.service

5. 安装Typecho到/var/www/html

  • 官网下载稳定版

$ wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz

  • 解压到/var/www/html/

$ tar -zxvf 1.1-17.10.30-release.tar.gz
# cp -rf 1.1-17.10.30-release/build /var/www/html

  • 打开ip跟随安装