typecho时隔四年,更新了1.2版本。 ## 升级系统 阿里轻量云最新的CentOS 8.2发行版,因为源已经关闭,无法正常使用dnf,因此选择迁移到AlmaLinux。迁移参考:[AlmaLinux/almalinux-deploy](https://github.com/AlmaLinux/almalinux-deploy)。 之所以选择RHEL8,是因为自带的软件比较新。可以省去自行编译的麻烦。 ## 安装软件运行环境 ### Nginx 默认的启用的Nginx模块为1.14版本,我选择启用最新的1.20。 ``` dnf module list nginx # 查看可用模块和状态 dnf module enable nginx:1.20 # 启用模块 dnf install nginx ``` ### PHP 默认启用的PHP模块版本为7.2,可以升级到更新的7.4。 ``` dnf module list php dnf module enable php:7.4 dnf install php ``` ### 安装必要的PHP拓展 根据Typecho和主题的要求,安装拓展模块。 我使用MySQL作为数据库,也需要安装对应的数据库驱动。 ``` dnf install php-mbstring php-pdo php-mysqlnd dnf install php-json ``` ### 测试环境状态 添加虚拟主机。 ``` cat > /etc/nginx/conf.d/simaek.com.conf << EOF server { listen 80; server_name nat.simaek.cn; root /home/www/simaek.com; index index.php; location ~ [^/]\.php(/|$) { include fastcgi.conf; fastcgi_pass php-fpm; } } EOF ``` 添加PHP主页。 ``` cat > /home/www/simaek.com/index.php << EOF EOF ``` 启动nginx和php-fpm服务,测试环境运行是否正常。 ``` systemctl enable --now nginx systemctl enable --now php-fpm ``` ### 数据库安装 我使用MariaDB数据库。 RHEL8默认的MySQL数据库版本已经是8.0起步了,如果想使用低版本,可以考虑MariaDB,最低版本为10.3,也有10.5可选。 ``` dnf module list mariadb dnf install mariadb mariadb-server ``` 开启数据库服务,并安全初始化数据库。根据提示配置root用户密码和权限等。 ``` systemctl enable --now mariadb mysql_secure_installation ``` ### 应用迁移 从备份中将网站根目录数据,复制到新环境对应位置。 将数据库备份导入到新数据库。 > 数据库迁移不在此篇文章讨论范畴内。 修改应用配置,更改数据库连接配置。配置文件位于网站根目录`config.inc.php`文件。 ## 异常排查 ### 原来开启了伪静态,现在没有相关配置,导致所有链接无法正常访问 添加伪静态配置。 ``` server { listen 80; server_name nat.simaek.cn; root /home/www/simaek.com; index index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location ~ [^/]\.php(/|$) { include fastcgi.conf; fastcgi_pass php-fpm; } } ``` ### 开启HTTPS 拷贝原来的证书到nginx配置目录,添加ssl配置。 ``` server { # --snip-- ssl_certificate ssl/simaek.com/simaek.com.pem; ssl_certificate_key ssl/simaek.com/simaek.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"; ssl_session_cache builtin:1000 shared:SSL:10m; # openssl dhparam -out ssl/dhparam.pem 2048 ssl_dhparam ssl/dhparam.pem; } ``` ### HTTPS跳转和域名www跳转 ``` server { # --snip-- if ($host !~ "(^www.simaek.com$)") { rewrite ^(.*) https://www.simaek.com$1 permanent; } if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } } ``` Loading... typecho时隔四年,更新了1.2版本。 ## 升级系统 阿里轻量云最新的CentOS 8.2发行版,因为源已经关闭,无法正常使用dnf,因此选择迁移到AlmaLinux。迁移参考:[AlmaLinux/almalinux-deploy](https://github.com/AlmaLinux/almalinux-deploy)。 之所以选择RHEL8,是因为自带的软件比较新。可以省去自行编译的麻烦。 ## 安装软件运行环境 ### Nginx 默认的启用的Nginx模块为1.14版本,我选择启用最新的1.20。 ``` dnf module list nginx # 查看可用模块和状态 dnf module enable nginx:1.20 # 启用模块 dnf install nginx ``` ### PHP 默认启用的PHP模块版本为7.2,可以升级到更新的7.4。 ``` dnf module list php dnf module enable php:7.4 dnf install php ``` ### 安装必要的PHP拓展 根据Typecho和主题的要求,安装拓展模块。 我使用MySQL作为数据库,也需要安装对应的数据库驱动。 ``` dnf install php-mbstring php-pdo php-mysqlnd dnf install php-json ``` ### 测试环境状态 添加虚拟主机。 ``` cat > /etc/nginx/conf.d/simaek.com.conf << EOF server { listen 80; server_name nat.simaek.cn; root /home/www/simaek.com; index index.php; location ~ [^/]\.php(/|$) { include fastcgi.conf; fastcgi_pass php-fpm; } } EOF ``` 添加PHP主页。 ``` cat > /home/www/simaek.com/index.php << EOF <?php echo phpinfo(); ?> EOF ``` 启动nginx和php-fpm服务,测试环境运行是否正常。 ``` systemctl enable --now nginx systemctl enable --now php-fpm ``` ### 数据库安装 我使用MariaDB数据库。 RHEL8默认的MySQL数据库版本已经是8.0起步了,如果想使用低版本,可以考虑MariaDB,最低版本为10.3,也有10.5可选。 ``` dnf module list mariadb dnf install mariadb mariadb-server ``` 开启数据库服务,并安全初始化数据库。根据提示配置root用户密码和权限等。 ``` systemctl enable --now mariadb mysql_secure_installation ``` ### 应用迁移 从备份中将网站根目录数据,复制到新环境对应位置。 将数据库备份导入到新数据库。 > 数据库迁移不在此篇文章讨论范畴内。 修改应用配置,更改数据库连接配置。配置文件位于网站根目录`config.inc.php`文件。 ## 异常排查 ### 原来开启了伪静态,现在没有相关配置,导致所有链接无法正常访问 添加伪静态配置。 ``` server { listen 80; server_name nat.simaek.cn; root /home/www/simaek.com; index index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location ~ [^/]\.php(/|$) { include fastcgi.conf; fastcgi_pass php-fpm; } } ``` ### 开启HTTPS 拷贝原来的证书到nginx配置目录,添加ssl配置。 ``` server { # --snip-- ssl_certificate ssl/simaek.com/simaek.com.pem; ssl_certificate_key ssl/simaek.com/simaek.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"; ssl_session_cache builtin:1000 shared:SSL:10m; # openssl dhparam -out ssl/dhparam.pem 2048 ssl_dhparam ssl/dhparam.pem; } ``` ### HTTPS跳转和域名www跳转 ``` server { # --snip-- if ($host !~ "(^www.simaek.com$)") { rewrite ^(.*) https://www.simaek.com$1 permanent; } if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } } ``` 最后修改:2022 年 06 月 07 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 4 如果觉得我的文章对你有用,请随意赞赏