UTF-8 – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Wed, 03 Jun 2026 13:31:18 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 Ubuntu 打开 Windows 文档提示“无效字符”?我的解决方法 https://www.shuijingwanwq.com/2026/06/03/15636/ https://www.shuijingwanwq.com/2026/06/03/15636/#respond Wed, 03 Jun 2026 13:31:16 +0000 https://www.shuijingwanwq.com/?p=15636 浏览量: 39

从 Windows 换到 Ubuntu 后,打开以前写的文档时弹出了“检测到无效字符”的提示,内容显示为乱码。这里记录一下我亲测有效的解决方法,全程只需鼠标操作。

一、问题现象

在 Ubuntu 26.04 系统中,使用系统自带的文本编辑器(GNOME 默认编辑器)打开一个之前在 Windows 10 下编写的 .txt 文档时,弹出一个错误提示:

检测到无效字符
发生了编码转换错误因此使用了回退字符。

检测到无效字符
发生了编码转换错误因此使用了回退字符。

文档内容显示为一堆类似 D6C0E0CFC2B5C4... 的乱码,无法阅读。

二、原因简析

这个问题通常是因为 Windows 和 Linux 默认使用的文字编码不同。

  • Windows 10(简体中文版)默认使用 GBK(或 GB18030)编码保存文本文件。
  • Ubuntu 默认使用 UTF-8 编码。

Ubuntu 的文本编辑器自动检测编码时,误把 GBK 文件当成 UTF-8 去打开,遇到无法识别的字节就报了“无效字符”的错误。

三、解决步骤(全程鼠标操作)

以下是我实际操作的过程。

第 1 步:手动将编码改为 GBK

  1. 弹出“检测到无效字符”对话框时,点击其中的 「更改编码(E)…」 按钮。
  2. 在弹出的“更改编码”窗口中,默认选中的是 UTF-8
    从列表中找到并选择 简体中文 (GBK)(也可以选择 GB18030 或 GB2312)。

我选择的是 GBK。

此时编辑器会使用 GBK 编码重新加载文档,内容恢复正常,中英文均可正确显示。

此时编辑器会使用 GBK 编码重新加载文档,内容恢复正常,中英文均可正确显示。

第 2 步:将文档另存为 UTF-8(覆盖原文件)

虽然文档已经可以正常阅读,但它本质上还是 GBK 编码。为了以后在任何 Linux 环境下都能直接打开,可以把它转换成 Ubuntu 通用的 UTF-8 编码。

操作如下:

  1. 点击编辑器菜单栏 另存为
  2. 在保存对话框中找到 显示选项 – 编码 ,将其从“自动检测”改为 UTF-8
  3. 保持文件名和路径不变(覆盖原文件),点击 替换
  4. 关闭文档,再重新打开。
在保存对话框中找到 显示选项 - 编码 ,将其从“自动检测”改为 UTF-8。

重新打开后不再出现错误提示,内容完美显示。这个文件以后在大多数现代编辑器中(包括 Windows 下的新版本记事本)也可以正常打开。

四、如何避免以后再次遇到类似问题

如果经常需要在 Ubuntu 中打开从 Windows 拷贝过来的文本文件,可以尝试以下的习惯。

在 Windows 下创建文件时直接保存为 UTF-8(我大部分文件皆是 UTF-8)

  • 使用 Windows 自带的 记事本:编辑完成后点击“文件”→“另存为”,在“编码”下拉框中选择 UTF-8
  • 使用 Notepad++:打开文件后点击菜单“编码”→“转为 UTF-8 无 BOM 编码”。这样保存的文件在 Ubuntu 下兼容性更好。

五、总结

遇到“无效字符”错误时,只需两步即可解决:

  1. 更改编码为 GBK → 让文档正常显示。
  2. 另存为 UTF-8 → 永久解决编码问题。

整个过程不需要使用命令行,在图形界面中点几下鼠标就可以完成。希望这次记录能对遇到类似情况的朋友有所帮助。

]]>
https://www.shuijingwanwq.com/2026/06/03/15636/feed/ 0
preg_split 执行中文后的结果,有乱码 https://www.shuijingwanwq.com/2025/05/24/9042/ https://www.shuijingwanwq.com/2025/05/24/9042/#respond Sat, 24 May 2025 05:59:25 +0000 多选一 [1] => 多选二 )]]> https://www.shuijingwanwq.com/?p=9042 浏览量: 64 1、preg_split 执行中文后的结果,有乱码。如图1
preg_split 执行中文后的结果,有乱码。

图1



$optionText = '多选一,多选二';
$optionInputs = preg_split('/[\r\n,,;;、]+/', $optionText);


2、在使用 preg_split() 之前,先将字符串转换为 UTF-8。u 表示 Unicode(UTF-8)模式,避免中文字符拆分错误。


$optionText = mb_convert_encoding('多选一,多选二', 'UTF-8', 'auto');
$optionInputs = preg_split('/[\r\n,,;;、]+/u', $optionText);



3、拆分正确,不再报错。


Array ( [0] => 多选一 [1] => 多选二 )


]]>
https://www.shuijingwanwq.com/2025/05/24/9042/feed/ 0
Laravel 8.x 部署至 Heroku,基于 PostgreSQL 实现 https://www.shuijingwanwq.com/2021/12/29/5622/ https://www.shuijingwanwq.com/2021/12/29/5622/#respond Wed, 29 Dec 2021 11:20:55 +0000 https://www.shuijingwanwq.com/?p=5622 浏览量: 114 1、在本地开发环境中,基于 Laravel Sail 已经部署完毕。打开网址:http://weibo.test/ ,响应 200。如图1
在本地开发环境中,基于 Laravel Sail 已经部署完毕。打开网址:http://weibo.test/ ,响应 200。

图1

2、注册一个 Heroku 账号,使用 @163.com ,发现不被允许,最后使用 @gmail.com,才注册成功。如图2
注册一个 Heroku 账号,使用 @163.com ,发现不被允许,最后使用 @gmail.com,才注册成功。

图2

3、在邮箱 @gmail.com 中点击链接以激活帐户。如图3
在邮箱 @gmail.com 中点击链接以激活帐户。

图3

4、参考网址:https://devcenter.heroku.com/articles/heroku-cli 。Heroku 命令行界面 (CLI) 使直接从终端创建和管理 Heroku 应用程序变得容易。 这是使用 Heroku 的重要组成部分。 5、在 WSL2 中的 Ubuntu 系统中,从终端运行以下命令。报错:error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory。如图4
在 WSL2 中的 Ubuntu 系统中,从终端运行以下命令。报错:error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory。

图4



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sudo snap install --classic heroku
error: cannot communicate with server: Post http://localhost/v2/snaps/heroku: dial unix /run/snapd.socket: connect: no such file or directory


6、最终决定使用 Windows 下的软件。为您的 Windows 安装下载合适的安装程序。如图5
最终决定使用 Windows 下的软件。为您的 Windows 安装下载合适的安装程序。

图5

7、安装过程中报错:Error opening file for writing。如图6
安装过程中报错:Error opening file for writing。

图6



Error opening file for writing:

D:\Program Files\heroku\client\bin\node.exe

Click Abort to stop the installation,
Retry to try again, or
Ignore to skip this file.


8、重新安装,以管理员身份运行,不再报错。 9、验证您的安装,要验证您的 CLI 安装,请使用 heroku –version 命令。已经成功安装。如图7
验证您的安装,要验证您的 CLI 安装,请使用 heroku --version 命令。已经成功安装。

图7



PS C:\Users\Lenovo> heroku --version
 »   Warning: Our terms of service have changed: https://dashboard.heroku.com/terms-of-service
heroku/7.53.0 win32-x64 node-v12.21.0
PS C:\Users\Lenovo>


10、安装 CLI 后,运行 heroku login 命令。 系统会提示您输入任意键以转到 Web 浏览器以完成登录。 然后 CLI 会自动让您登录。如图8
安装 CLI 后,运行 heroku login 命令。 系统会提示您输入任意键以转到 Web 浏览器以完成登录。 然后 CLI 会自动让您登录。

图8



PS C:\Users\Lenovo> heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/056bdba3-dbeb-43ee-9ffc-9556ce91ee23?requestor=SFMyNTY.g2gDbQAAAA42Ni4xNzUuMjE2LjIzOW4GAMhVMuV9AWIAAVGA.7UEaCXMegvnax1AIZ5H_XignHykfVPEHFYcOP0NL2uI
Logging in... done
Logged in as shuijingwanwq@gmail.com
PS C:\Users\Lenovo>


11、参考网址:https://devcenter.heroku.com/articles/getting-started-with-php 。因为文档假设 PHP 与 Composer 安装在本地。由于本地环境的 PHP 版本与 Laravel Sail 环境中的版本不一致,决定先将本地环境的 PHP 版本升级至 PHP 8.1。如图9、图10
因为文档假设 PHP 与 Composer 安装在本地。

图9

 
由于本地环境的 PHP 版本与 Laravel Sail 环境中的版本不一致,决定先将本地环境的 PHP 版本升级至 PHP 8.1。

图10

本地环境的版本号:


PS C:\Users\Lenovo> php -v
PHP 7.4.27 (cli) (built: Dec 14 2021 19:52:13) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
PS C:\Users\Lenovo> composer -V
Composer version 2.1.14 2021-11-30 10:51:43
PS C:\Users\Lenovo>


Laravel Sail 环境的版本号:


# php -v
PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
# composer -V
Composer version 2.1.14 2021-11-30 10:51:43
#


12、升级后的本地环境的 PHP 版本,PHP 8.1.1。


PS C:\Users\Lenovo> php -v
PHP 8.1.1 (cli) (built: Dec 15 2021 10:31:43) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
PS C:\Users\Lenovo>


13、进入程序根目录,使用 heroku create 命令在 Heroku 上创建一个新应用。secret-stream-72395 是 Heroku 随机为应用生成的默认名称,每个人生成的名称都不相同。而 https://secret-stream-72395.herokuapp.com/ 则是应用的线上地址。如图11
进入程序根目录,使用 heroku create 命令在 Heroku 上创建一个新应用。secret-stream-72395 是 Heroku 随机为应用生成的默认名称,每个人生成的名称都不相同。而 https://secret-stream-72395.herokuapp.com/ 则是应用的线上地址。

图11



PS E:\wwwroot> cd .\weibo\
PS E:\wwwroot\weibo> heroku create
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Creating app... done, ⬢ secret-stream-72395
https://secret-stream-72395.herokuapp.com/ | https://git.heroku.com/secret-stream-72395.git
PS E:\wwwroot\weibo>


14、Heroku 平台支持多种语言,在进行应用部署时,Heroku 会自动检查应用的代码是用什么语言写的,然后再接着执行一系列针对该语言的操作来准备好程序运行环境。Laravel 应用默认会包含 package.json 文件,但当 Heroku 检查到该文件时,它会认为此应用是用 Node.js 写的,因此我们需要对应用的 buildpack 进行声明,告诉 Heroku 说我们的应用是用 PHP 写的。如图12
对应用的 buildpack 进行声明,告诉 Heroku 说我们的应用是用 PHP 写的

图12



PS E:\wwwroot\weibo> heroku buildpacks:set heroku/php
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Buildpack set. Next release on secret-stream-72395 will use heroku/php.
Run git push heroku main to create a new release using this buildpack.
PS E:\wwwroot\weibo>


15、将代码推送和部署到 Heroku 上。如图13
将代码推送和部署到 Heroku 上

图13

<pre class="wp-block-syntaxhighlighter-code">

PS E:\wwwroot\weibo> git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   docker-compose.yml

PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 195, done.
Counting objects: 100% (195/195), done.
Delta compression using up to 4 threads
Compressing objects: 100% (169/169), done.
Writing objects: 100% (195/195), 651.34 KiB | 1.41 MiB/s, done.
Total 195 (delta 47), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Downloading doctrine/inflector (2.0.4)
remote:          - Downloading doctrine/lexer (1.2.1)
remote:          - Downloading symfony/polyfill-ctype (v1.23.0)
remote:          - Downloading webmozart/assert (1.10.0)
remote:          - Downloading dragonmantank/cron-expression (v3.1.0)
remote:          - Downloading symfony/polyfill-php80 (v1.23.1)
remote:          - Downloading symfony/polyfill-php73 (v1.23.0)
remote:          - Downloading symfony/polyfill-mbstring (v1.23.1)
remote:          - Downloading symfony/deprecation-contracts (v3.0.0)
remote:          - Downloading symfony/http-foundation (v5.4.1)
remote:          - Downloading psr/event-dispatcher (1.0.0)
remote:          - Downloading symfony/event-dispatcher-contracts (v3.0.0)
remote:          - Downloading symfony/event-dispatcher (v6.0.1)
remote:          - Downloading symfony/var-dumper (v5.4.1)
remote:          - Downloading psr/log (2.0.0)
remote:          - Downloading symfony/error-handler (v5.4.1)
remote:          - Downloading symfony/http-kernel (v5.4.1)
remote:          - Downloading voku/portable-ascii (1.5.6)
remote:          - Downloading phpoption/phpoption (1.8.1)
remote:          - Downloading graham-campbell/result-type (v1.0.4)
remote:          - Downloading vlucas/phpdotenv (v5.4.1)
remote:          - Downloading symfony/css-selector (v6.0.1)
remote:          - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
remote:          - Downloading symfony/routing (v5.4.0)
remote:          - Downloading symfony/process (v5.4.0)
remote:          - Downloading symfony/polyfill-php72 (v1.23.0)
remote:          - Downloading symfony/polyfill-intl-normalizer (v1.23.0)
remote:          - Downloading symfony/polyfill-intl-idn (v1.23.0)
remote:          - Downloading symfony/mime (v5.4.0)
remote:          - Downloading symfony/finder (v5.4.0)
remote:          - Downloading symfony/polyfill-intl-grapheme (v1.23.1)
remote:          - Downloading symfony/string (v6.0.1)
remote:          - Downloading psr/container (1.1.2)
remote:          - Downloading symfony/service-contracts (v2.4.1)
remote:          - Downloading symfony/console (v5.4.1)
remote:          - Downloading symfony/polyfill-iconv (v1.23.0)
remote:          - Downloading egulias/email-validator (2.1.25)
remote:          - Downloading swiftmailer/swiftmailer (v6.3.0)
remote:          - Downloading symfony/polyfill-php81 (v1.23.0)
remote:          - Downloading ramsey/collection (1.2.2)
remote:          - Downloading brick/math (0.9.3)
remote:          - Downloading ramsey/uuid (4.2.3)
remote:          - Downloading psr/simple-cache (1.0.1)
remote:          - Downloading opis/closure (3.6.2)
remote:          - Downloading symfony/translation-contracts (v3.0.0)
remote:          - Downloading symfony/translation (v6.0.1)
remote:          - Downloading nesbot/carbon (2.55.2)
remote:          - Downloading monolog/monolog (2.3.5)
remote:          - Downloading league/mime-type-detection (1.9.0)
remote:          - Downloading league/flysystem (1.1.9)
remote:          - Downloading nette/utils (v3.2.6)
remote:          - Downloading nette/schema (v1.2.2)
remote:          - Downloading dflydev/dot-access-data (v3.0.1)
remote:          - Downloading league/config (v1.1.1)
remote:          - Downloading league/commonmark (2.1.0)
remote:          - Downloading laravel/serializable-closure (v1.0.5)
remote:          - Downloading laravel/framework (v8.76.2)
remote:          - Downloading asm89/stack-cors (v2.0.3)
remote:          - Downloading fruitcake/laravel-cors (v2.0.4)
remote:          - Downloading psr/http-message (1.0.1)
remote:          - Downloading psr/http-client (1.0.1)
remote:          - Downloading ralouphie/getallheaders (3.0.3)
remote:          - Downloading psr/http-factory (1.0.1)
remote:          - Downloading guzzlehttp/psr7 (2.1.0)
remote:          - Downloading guzzlehttp/promises (1.5.1)
remote:          - Downloading guzzlehttp/guzzle (7.4.1)
remote:          - Downloading laravel/sanctum (v2.13.0)
remote:          - Downloading nikic/php-parser (v4.13.2)
remote:          - Downloading psy/psysh (v0.10.12)
remote:          - Downloading laravel/tinker (v2.6.3)
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote:        NOTICE: No Procfile, using 'web: heroku-php-apache2'.
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.8M
remote: -----> Launching...
remote:        Released v3
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
 * [new branch]      main -> main
PS E:\wwwroot\weibo>

</pre>
16、应用程序现已部署。 确保至少有一个应用实例正在运行,现在通过应用程序名称生成的 URL 访问该应用程序。 作为一个方便的快捷方式,您可以按如下方式打开网站。如图14
应用程序现已部署。 确保至少有一个应用实例正在运行,现在通过应用程序名称生成的 URL 访问该应用程序。 作为一个方便的快捷方式,您可以按如下方式打开网站。

图14



PS E:\wwwroot\weibo> heroku ps:scale web=1
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Scaling dynos... done, now running web at 1:Free
PS E:\wwwroot\weibo> heroku open
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
PS E:\wwwroot\weibo>


17、但是,在浏览器中自动打开网站:https://secret-stream-72395.herokuapp.com/ ,响应 403。如图15
但是,在浏览器中自动打开网站:https://secret-stream-72395.herokuapp.com/ ,响应 403。

图15



Forbidden
You don't have permission to access this resource.


18、在步骤 15 中提示:No Procfile, using ‘web: heroku-php-apache2’。Laravel 项目下新建一个 Procfile 文件,通过配置该文件来告诉 Heroku 应当使用什么命令来启动 Web 服务器。接着还需要将该文件纳入到 Git 版本控制中。报错:Push failed: cannot parse Procfile.。如图16
报错:Push failed: cannot parse Procfile.

图16



PS E:\wwwroot\weibo> echo web: vendor/bin/heroku-php-apache2 public/ > Procfile
PS E:\wwwroot\weibo> git add -A
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main 64256ed] Procfile for Heroku
 2 files changed, 6 insertions(+), 6 deletions(-)
 create mode 100644 Procfile
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 496 bytes | 496.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:
remote:  !     Push failed: cannot parse Procfile.
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see https://help.heroku.com/ and provide Request ID f09b381f-8217-327d-d121-119f1e8d0c31.
remote:
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to secret-stream-72395.
remote:
To https://git.heroku.com/secret-stream-72395.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/secret-stream-72395.git'
PS E:\wwwroot\weibo>


19、查看文件 Procfile 的内容,如图17
查看文件 Procfile 的内容

图17



web:
vendor/bin/heroku-php-apache2
public/



20、参考 Getting Started with Laravel on Heroku:https://devcenter.heroku.com/articles/getting-started-with-laravel 。查看文件 Procfile 的内容,如图18
参考 Getting Started with Laravel on Heroku:https://devcenter.heroku.com/articles/getting-started-with-laravel 。查看文件 Procfile 的内容

图18



PS E:\wwwroot\weibo> echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
PS E:\wwwroot\weibo> git add .
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main a30f3dd] Procfile for Heroku
 1 file changed, 0 insertions(+), 0 deletions(-)


21、设置 Laravel 加密密钥,使用 Laravel 自带的 artisan 命令来生成 App Key。如图19
设置 Laravel 加密密钥,使用 Laravel 自带的 artisan 命令来生成 App Key。

图19



PS E:\wwwroot\weibo> php artisan key:generate --show
base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
PS E:\wwwroot\weibo>


22、基于生成的 App Key ,运行该命令行来完成配置。如图20
基于生成的 App Key ,运行该命令行来完成配置。

图20



PS E:\wwwroot\weibo> heroku config:set APP_KEY=base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Setting APP_KEY and restarting ⬢ secret-stream-72395... done, v4
APP_KEY: base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
PS E:\wwwroot\weibo>


23、推送时,仍然报错:Push failed: cannot parse Procfile.
<pre class="wp-block-syntaxhighlighter-code">

PS E:\wwwroot\weibo> git push heroku main:main
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (17/17), 1.59 KiB | 542.00 KiB/s, done.
Total 17 (delta 8), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:
remote:  !     Push failed: cannot parse Procfile.
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see https://help.heroku.com/ and provide Request ID 691561db-a116-53f5-a4e5-0100a3777ce9.
remote:
remote:
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: a30f3dde79d674408b2fb440cda5f9dbeb2204fe
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version a30f3dde79d674408b2fb440cda5f9dbeb2204fe
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to secret-stream-72395.
remote:
To https://git.heroku.com/secret-stream-72395.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/secret-stream-72395.git'
PS E:\wwwroot\weibo>

</pre>
24、将文件编码另存为 UTF-8 。如图21
将文件编码另存为 UTF-8 。

图21

25、推送成功,且打开网址:https://secret-stream-72395.herokuapp.com/ ,响应 200。如图22
推送成功,且打开网址:https://secret-stream-72395.herokuapp.com/ ,响应 200。

图22



PS E:\wwwroot\weibo> git add .
PS E:\wwwroot\weibo> git commit -m "Procfile for Heroku"
[main 362c878] Procfile for Heroku
 1 file changed, 0 insertions(+), 0 deletions(-)
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 4 threads
Compressing objects: 100% (19/19), done.
Writing objects: 100% (20/20), 1.84 KiB | 470.00 KiB/s, done.
Total 20 (delta 9), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 70 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Package manifest generated successfully.
remote:        49 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.8M
remote: -----> Launching...
remote:        Released v6
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
   e72b466..362c878  main -> main
PS E:\wwwroot\weibo> heroku open
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
PS E:\wwwroot\weibo>


26、但是,在提交表单,写入数据至 MySQL 时,响应 500 服务器错误,原因在于数据库还不存在。如图23
在提交表单,写入数据至 MySQL 时,响应 500 服务器错误,原因在于数据库还不存在。

图23

27、在 Heroku 上使用 PostgreSQL 来作为我们应用的数据库。安装 PostgreSQL 扩展。Heroku 将为我们生成一个唯一的数据库 URL – DATABASE_URL,我们可以通过命令:heroku config 查看 Heroku 的所有配置信息。如图24
在 Heroku 上使用 PostgreSQL 来作为我们应用的数据库。安装 PostgreSQL 扩展。Heroku 将为我们生成一个唯一的数据库 URL - DATABASE_URL,我们可以通过命令:heroku config 查看 Heroku 的所有配置信息。

图24



PS E:\wwwroot\weibo> heroku addons:add heroku-postgresql:hobby-dev
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Creating heroku-postgresql:hobby-dev on ⬢ secret-stream-72395... free
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Created postgresql-parallel-13694 as DATABASE_URL
Use heroku addons:docs heroku-postgresql to view documentation
PS E:\wwwroot\weibo> heroku config
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
=== secret-stream-72395 Config Vars
APP_KEY:      base64:TXoum9anbYcE/VGilCjxrSQQ5E4cR5UVb+55SjIsbg0=
DATABASE_URL: postgres://eayusxxdstiniz:31d9e092c4c8d1740380641299d36711b04e72b98e2f92b9be4253153087bbea@ec2-52-200-28-255.compute-1.amazonaws.com:5432/d9nb3l2ot2cutp
PS E:\wwwroot\weibo>


28、在本地开发中,我们使用了 MySQL 来作为数据库储存,但在 Heroku 环境上我们要改为使用 PostgreSQL 来作为数据库储存。因此在进行数据库设置时,我们需要对当前环境进行判断。如果环境为本地环境,则使用 MySQL 数据库,若为 Heroku 环境,则使用 PostgreSQL 数据库。我们可以通过为 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。一般来说,应用的数据库都在 config/database.php 中进行配置,因此我们需要针对该配置文件,来为不同环境的数据库连接方式定义一个帮助方法,以便根据应用不同的运行环境来指定数据库配置信息,我们需要新建一个 helpers.php 文件并写入以下内容:
<pre class="wp-block-syntaxhighlighter-code">

<?php

function get_db_config()
{
    if (getenv('IS_IN_HEROKU')) {
        $url = parse_url(getenv("DATABASE_URL"));

        return $db_config = [
            'connection' => 'pgsql',
            'host' => $url["host"],
            'database'  => substr($url["path"], 1),
            'username'  => $url["user"],
            'password'  => $url["pass"],
        ];
    } else {
        return $db_config = [
            'connection' => env('DB_CONNECTION', 'mysql'),
            'host' => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
        ];
    }
}

</pre>
29、新增 helpers.php 文件之后,还需要在项目根目录下 composer.json 文件中的 autoload 选项里 files 字段加入该文件。如图25
新增 helpers.php 文件之后,还需要在项目根目录下 composer.json 文件中的 autoload 选项里 files 字段加入该文件。

图25



    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/helpers.php"
        ]
    },


30、修改保存后运行以下命令进行重新加载文件即可,如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令。如图26
修改保存后运行以下命令进行重新加载文件即可,如果有可能影响到本地环境的程序运行,建议在 Sail 环境中执行相应命令。

图26



wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ sail composer dump-autoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Package manifest generated successfully.
Generated optimized autoload files containing 5027 classes
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$


31、现在,让我们使用刚刚定义好的 get_db_config 方法对数据库进行配置。调整数据库配置文件,总计就 2 处改动。如图28
现在,让我们使用刚刚定义好的 get_db_config 方法对数据库进行配置。调整数据库配置文件,总计就 2 处改动。

图28

<pre class="wp-block-syntaxhighlighter-code">

<?php

use Illuminate\Support\Str;

$db_config = get_db_config();

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => $db_config['connection'],

</pre>
32、改动的代码进行提交,并推送到 GitHub 和 Heroku 上。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git push
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 936 bytes | 58.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
To https://github.com/shuijingwan/weibo.git
   876eb29..173fc8d  sign-up -> sign-up
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git merge sign-up
Merge made by the 'recursive' strategy.
 app/helpers.php     | 24 ++++++++++++++++++++++++
 composer.json       |  5 ++++-
 config/database.php |  4 +++-
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 app/helpers.php
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 300 bytes | 33.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/shuijingwan/weibo.git
   cd4e270..1e23962  main -> main
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/weibo$




PS E:\wwwroot\weibo> git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
PS E:\wwwroot\weibo> git push heroku main
Enumerating objects: 19, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 1.13 KiB | 576.00 KiB/s, done.
Total 9 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (8.1.1)
remote:        - ext-mbstring (bundled with php)
remote:        - composer (2.1.14)
remote:        - apache (2.4.51)
remote:        - nginx (1.20.2)
remote: -----> Installing dependencies...
remote:        Composer version 2.1.14 2021-11-30 10:51:43
remote:        Installing dependencies from lock file
remote:        Verifying lock file contents can be installed on current platform.
remote:        Package operations: 72 installs, 0 updates, 0 removals
remote:          - Installing doctrine/inflector (2.0.4): Extracting archive
remote:          - Installing doctrine/lexer (1.2.1): Extracting archive
remote:          - Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
remote:          - Installing webmozart/assert (1.10.0): Extracting archive
remote:          - Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
remote:          - Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
remote:          - Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
remote:          - Installing symfony/deprecation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/http-foundation (v5.4.1): Extracting archive
remote:          - Installing psr/event-dispatcher (1.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/event-dispatcher (v6.0.1): Extracting archive
remote:          - Installing symfony/var-dumper (v5.4.1): Extracting archive
remote:          - Installing psr/log (2.0.0): Extracting archive
remote:          - Installing symfony/error-handler (v5.4.1): Extracting archive
remote:          - Installing symfony/http-kernel (v5.4.1): Extracting archive
remote:          - Installing voku/portable-ascii (1.5.6): Extracting archive
remote:          - Installing phpoption/phpoption (1.8.1): Extracting archive
remote:          - Installing graham-campbell/result-type (v1.0.4): Extracting archive
remote:          - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
remote:          - Installing symfony/css-selector (v6.0.1): Extracting archive
remote:          - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
remote:          - Installing symfony/routing (v5.4.0): Extracting archive
remote:          - Installing symfony/process (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
remote:          - Installing symfony/mime (v5.4.0): Extracting archive
remote:          - Installing symfony/finder (v5.4.0): Extracting archive
remote:          - Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
remote:          - Installing symfony/string (v6.0.1): Extracting archive
remote:          - Installing psr/container (1.1.2): Extracting archive
remote:          - Installing symfony/service-contracts (v2.4.1): Extracting archive
remote:          - Installing symfony/console (v5.4.1): Extracting archive
remote:          - Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
remote:          - Installing egulias/email-validator (2.1.25): Extracting archive
remote:          - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
remote:          - Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
remote:          - Installing ramsey/collection (1.2.2): Extracting archive
remote:          - Installing brick/math (0.9.3): Extracting archive
remote:          - Installing ramsey/uuid (4.2.3): Extracting archive
remote:          - Installing psr/simple-cache (1.0.1): Extracting archive
remote:          - Installing opis/closure (3.6.2): Extracting archive
remote:          - Installing symfony/translation-contracts (v3.0.0): Extracting archive
remote:          - Installing symfony/translation (v6.0.1): Extracting archive
remote:          - Installing nesbot/carbon (2.55.2): Extracting archive
remote:          - Installing monolog/monolog (2.3.5): Extracting archive
remote:          - Installing league/mime-type-detection (1.9.0): Extracting archive
remote:          - Installing league/flysystem (1.1.9): Extracting archive
remote:          - Installing nette/utils (v3.2.6): Extracting archive
remote:          - Installing nette/schema (v1.2.2): Extracting archive
remote:          - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
remote:          - Installing league/config (v1.1.1): Extracting archive
remote:          - Installing league/commonmark (2.1.0): Extracting archive
remote:          - Installing laravel/serializable-closure (v1.0.5): Extracting archive
remote:          - Installing laravel/framework (v8.76.2): Extracting archive
remote:          - Installing asm89/stack-cors (v2.0.3): Extracting archive
remote:          - Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
remote:          - Installing psr/http-message (1.0.1): Extracting archive
remote:          - Installing psr/http-client (1.0.1): Extracting archive
remote:          - Installing ralouphie/getallheaders (3.0.3): Extracting archive
remote:          - Installing psr/http-factory (1.0.1): Extracting archive
remote:          - Installing guzzlehttp/psr7 (2.1.0): Extracting archive
remote:          - Installing guzzlehttp/promises (1.5.1): Extracting archive
remote:          - Installing guzzlehttp/guzzle (7.4.1): Extracting archive
remote:          - Installing laravel/sanctum (v2.13.0): Extracting archive
remote:          - Installing nikic/php-parser (v4.13.2): Extracting archive
remote:          - Installing psy/psysh (v0.10.12): Extracting archive
remote:          - Installing laravel/tinker (v2.6.3): Extracting archive
remote:          - Installing laravel-lang/lang (5.0.0): Extracting archive
remote:          - Installing overtrue/laravel-lang (4.2.2): Extracting archive
remote:        Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:        Discovered Package: fruitcake/laravel-cors
remote:        Discovered Package: laravel/sanctum
remote:        Discovered Package: laravel/tinker
remote:        Discovered Package: nesbot/carbon
remote:        Discovered Package: overtrue/laravel-lang
remote:        Package manifest generated successfully.
remote:        50 packages you are using are looking for funding.
remote:        Use the `composer fund` command to find out more!
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 19.9M
remote: -----> Launching...
remote:        Released v10
remote:        https://secret-stream-72395.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-stream-72395.git
   cd4e270..1e23962  main -> main
PS E:\wwwroot\weibo>


33、我们可以使用 heroku run 在 Heroku 运行 Laravel 的指定命令。现在我们需要在 Heroku 上执行迁移,生成用户表,可通过下面命令来完成,报错:SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter “client_encoding”: “utf8mb4” 。如图28
我们可以使用 heroku run 在 Heroku 运行 Laravel 的指定命令。现在我们需要在 Heroku 上执行迁移,生成用户表,可通过下面命令来完成,报错:SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter "client_encoding": "utf8mb4" 。

图28

 


PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.1841 (Free)
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes


In Connection.php line 703:

  SQLSTATE[22023]: Invalid parameter value: 7 ERROR:  invalid value for parameter "client_encoding": "utf8mb4" (SQL:
  select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'B
  ASE TABLE')


In PostgresConnector.php line 68:

  SQLSTATE[22023]: Invalid parameter value: 7 ERROR:  invalid value for parameter "client_encoding": "utf8mb4"


PS E:\wwwroot\weibo>


34、再次调整数据库配置文件,之前 pgsql 相关的配置未修改到。


        'pgsql' => [
            'driver' => 'pgsql',
            'host' => $db_config['host'],
            'port' => env('DB_PORT', '5432'),
            'database' => $db_config['database'],
            'username' => $db_config['username'],
            'password' => $db_config['password'],
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],


35、执行命令:heroku config:add DB_CONNECTION=pgsql 。再次执行迁移时报错已经不一样了:


 »   Warning: heroku update available from 7.53.0 to 7.59.2.
DB_CONNECTION: pgsql
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.7170 (Free)
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes


In Connection.php line 703:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections? (SQL: select * from information_schema.tables
   where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?


PS E:\wwwroot\weibo> git push heroku main
Everything up-to-date
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.6564 (Free)
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes


In Connection.php line 703:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections? (SQL: select * from information_schema.tables
   where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?


PS E:\wwwroot\weibo>


36、最后找到根源在于漏掉了在 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。迁移成功。如图29
最后找到根源在于漏掉了在 Heroku 新增一个 IS_IN_HEROKU 配置项来判断应用是否运行在 Heroku 上。迁移成功。

图29



PS E:\wwwroot\weibo> heroku config:set IS_IN_HEROKU=true
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Setting IS_IN_HEROKU and restarting ⬢ secret-stream-72395... done, v16
IS_IN_HEROKU: true
PS E:\wwwroot\weibo> heroku run php artisan migrate
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Running php artisan migrate on ⬢ secret-stream-72395... up, run.3491 (Free)
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (850.26ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (466.16ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (902.11ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (1,079.00ms)
PS E:\wwwroot\weibo>


37、再次提交表单数据,提交成功。如图30
再次提交表单数据,提交成功。

图30

38、使用 heroku rename 来对应用名称进行更改,但要保证更改的名称未被其它人占用。如图31
使用 heroku rename 来对应用名称进行更改,但要保证更改的名称未被其它人占用。

图31



PS E:\wwwroot\weibo> heroku rename app-wangqiang-weibo
 »   Warning: heroku update available from 7.53.0 to 7.59.2.
Renaming secret-stream-72395 to app-wangqiang-weibo... done
https://app-wangqiang-weibo.herokuapp.com/ | https://git.heroku.com/app-wangqiang-weibo.git
 !    Don't forget to update git remotes for all other local checkouts of the app.
Git remote heroku updated
PS E:\wwwroot\weibo>


39、打开:https://app-wangqiang-weibo.herokuapp.com/ ,响应 200。符合预期。如图32
打开:https://app-wangqiang-weibo.herokuapp.com/ ,响应 200。符合预期。

图32

40、打开:https://secret-stream-72395.herokuapp.com/ ,响应 404。There’s nothing here, yet。符合预期。如图33
打开:https://secret-stream-72395.herokuapp.com/ ,响应 404。There's nothing here, yet。符合预期。

图33

]]>
https://www.shuijingwanwq.com/2021/12/29/5622/feed/ 0
通过 FlashFXP 上传后的文件,HTTP 访问时响应 404 的排查分析 https://www.shuijingwanwq.com/2021/07/14/5064/ https://www.shuijingwanwq.com/2021/07/14/5064/#respond Wed, 14 Jul 2021 08:51:34 +0000 https://www.shuijingwanwq.com/?p=5064 浏览量: 64 1、通过 FlashFXP 上传文件:秦时明月第一集荧惑守心.mp4 至:/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4。如图1
通过 FlashFXP 上传文件:秦时明月第一集荧惑守心.mp4 至:/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4

图1

2、HTTP 访问:https://www.shuijingwanwq.com/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4 时响应 404。如图2
HTTP 访问:https://www.shuijingwanwq.com/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4 时响应 404。

图2

3、基于 PuTTY 登录 CentOS 服务器,进入目录:/wp-content/uploads/2021/07/。发现文件:秦时明月第一集荧惑守心.mp4 的文件名乱码。如图3
基于 PuTTY 登录 CentOS 服务器,进入目录:/wp-content/uploads/2021/07/。发现文件:秦时明月第一集荧惑守心.mp4 的文件名乱码。

图3

4、选择“Sites”–下拉菜单中点击“Site Manager”,然后选中站点(这里选择的是www.shuijingwanwq.com),在右侧工具栏中点击“Options”,导航至【Character Encoding】栏,设置为 UTF-8,然后重新连接下即可。如图4
选择“Sites”–下拉菜单中点击“Site Manager”,然后选中站点(这里选择的是www.shuijingwanwq.com),在右侧工具栏中点击“Options”,导航至【Character Encoding】栏,设置为 UTF-8,然后重新连接下即可。

图4

5、重新上传:秦时明月第一集荧惑守心.mp4 至:/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4。在目录:/wp-content/uploads/2021/07/ 下存在 2 个同名的文件。如图5
重新上传:秦时明月第一集荧惑守心.mp4 至:/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4。在目录:/wp-content/uploads/2021/07/ 下存在 2 个同名的文件。

图5

6、登录服务器,进入目录:/wp-content/uploads/2021/07/。删除文件名乱码的文件。如图6
登录服务器,进入目录:/wp-content/uploads/2021/07/。删除文件名乱码的文件。

图6



[root@iZ23wv7v5ggZ 07]# ls

2-4-768x538.png   4-3-720x340.png        ??ʱ???µ?һ??ӫ??????.mp4
2-4-80x80.png     4-3-768x435.png        兔子、牛、还有一只什么哟?认不出来了.mp4
2-4-895x450.png   4-3-80x80.png          发现小区居民楼旁边的主干道都在铺装降噪路面,效果还是挺明显的.mp4
2-4-895x500.png   4-3-980x450.png        发现小区居民楼旁边的主干道都在铺装降噪路面,效果还是挺明显的.webm
2-4.png           4-3.png                数一下,有几只红色的,有几只黄色的呢??.mp4
2-5-1024x515.png  4-4-149x300.png        秦时明月第一集荧惑守心.mp4
2-5-1035x500.png  4-4-150x150.png        精装海景房,您下楼就是这样的景色.mp4
2-5-150x150.png   4-4-320x320.png        龙泉的某个地方打疫苗,人还是这么多了.mp4
[root@iZ23wv7v5ggZ 07]# rm -rf ??ʱ???µ?һ??ӫ??????.mp4
[root@iZ23wv7v5ggZ 07]# ls
2-4-768x538.png   4-3-720x340.png        兔子、牛、还有一只什么哟?认不出来了.mp4
2-4-80x80.png     4-3-768x435.png        发现小区居民楼旁边的主干道都在铺装降噪路面,效果还是挺明显的.mp4
2-4-895x450.png   4-3-80x80.png          发现小区居民楼旁边的主干道都在铺装降噪路面,效果还是挺明显的.webm
2-4-895x500.png   4-3-980x450.png        数一下,有几只红色的,有几只黄色的呢??.mp4
2-4.png           4-3.png                秦时明月第一集荧惑守心.mp4
2-5-1024x515.png  4-4-149x300.png        精装海景房,您下楼就是这样的景色.mp4
2-5-1035x500.png  4-4-150x150.png        龙泉的某个地方打疫苗,人还是这么多了.mp4
2-5-150x150.png   4-4-320x320.png
[root@iZ23wv7v5ggZ 07]#



7、HTTP 访问:https://www.shuijingwanwq.com/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4 时响应 200。如图7
HTTP 访问:https://www.shuijingwanwq.com/wp-content/uploads/2021/07/秦时明月第一集荧惑守心.mp4 时响应 200

图7

 ]]>
https://www.shuijingwanwq.com/2021/07/14/5064/feed/ 0
在 Yii 2.0 中报错:Malformed UTF-8 characters, possibly incorrectly encoded. 的排查分析 https://www.shuijingwanwq.com/2021/04/13/4854/ https://www.shuijingwanwq.com/2021/04/13/4854/#respond Tue, 13 Apr 2021 05:34:10 +0000 https://www.shuijingwanwq.com/?p=4854 浏览量: 93

1、在 Yii 2.0 中报错:Malformed UTF-8 characters, possibly incorrectly encoded.


{
    "name": "Exception",
    "message": "Malformed UTF-8 characters, possibly incorrectly encoded.",
    "code": 5,
    "type": "yii\\base\\InvalidArgumentException",
    "file": "E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php",
    "line": 133,
    "stack-trace": [
        "#0 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php(67): yii\\helpers\\BaseJson::handleJsonError(5)",
        "#1 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(119): yii\\helpers\\BaseJson::encode('SQLSTATE[HY000]...', 320)",
        "#2 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(104): yii\\web\\JsonResponseFormatter->formatJson(Object(yii\\web\\Response))",
        "#3 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\Response.php(1070): yii\\web\\JsonResponseFormatter->format(Object(yii\\web\\Response))",
        "#4 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\Response.php(337): yii\\web\\Response->prepare()",
        "#5 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\base\\Application.php(392): yii\\web\\Response->send()",
        "#6 E:\\wwwroot\\pcs-api-feature-base-3.0\\api\\web\\index.php(17): yii\\base\\Application->run()",
        "#7 {main}"
    ]
}


2、查看代码如下

<?php
 
namespace api\rests\check_status;
 
use Yii;
use yii\web\HttpException;
use yii\base\Exception;
use yii\data\ActiveDataProvider;
use yii\data\DataFilter;
 
class IndexAction extends \yii\rest\IndexAction
{
    /**
     * @return int|string|ActiveDataProvider|DataFilter|null
     */
    public function run()
    {
        try {
            Yii::$app->db->open();
            if (!Yii::$app->redis->ping()){
                throw new HttpException(500, 'Redis is unavailable.');
            } elseif (!Yii::$app->db->getIsActive()){
                throw new HttpException(500, 'Database is unavailable.');
            } else {
                return 200;
            }
        } catch (Exception $e) {
            $res = Yii::$app->response;
            $res->statusCode = 500;
            return $e->getMessage();
        }
    }
}
 

3、打印输出 $e->getMessage(),其中包含乱码。如图1

打印输出 $e->getMessage(),其中包含乱码。

图1


SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: ��֪��������������


4、编辑代码,mb_convert_encoding — 转换字符的编码。响应状态码为:500,响应体为:”SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 “。如图2

编辑代码,mb_convert_encoding — 转换字符的编码。响应状态码为:500,响应体为:"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 "。

图2

<?php
 
namespace api\rests\check_status;
 
use Yii;
use yii\web\HttpException;
use yii\base\Exception;
use yii\data\ActiveDataProvider;
use yii\data\DataFilter;
 
class IndexAction extends \yii\rest\IndexAction
{
    /**
     * @return array|false|int|string|string[]|ActiveDataProvider|DataFilter|null
     */
    public function run()
    {
        try {
            Yii::$app->db->open();
            if (!Yii::$app->redis->ping()){
                throw new HttpException(500, 'Redis is unavailable.');
            } elseif (!Yii::$app->db->getIsActive()){
                throw new HttpException(500, 'Database is unavailable.');
            } else {
                return 200;
            }
        } catch (Exception $e) {
            Yii::$app->response->statusCode = 500;
            $message = mb_convert_encoding($e->getMessage(), "UTF-8", ["UTF-8", "GBK", "GB2312", "BIG5"]);
            return $message;
        }
    }
}

5、初步推测,不知道这样的主机是由 Windows 10 系统返回的。与是否是中文无甚关系,而是与中文本身的编码存在关系。因为 message 为:”Failed to open redis DB connection (tcp://localhost:63799, database=57): 10061 – 由于目标计算机积极拒绝,无法连接。\r\n” 时,未转换字符的编码也是可以正常运行的。

]]>
https://www.shuijingwanwq.com/2021/04/13/4854/feed/ 0
在 Windows 10 64、PHP 5.6 下重命名中文名文件,提示错误的解决 https://www.shuijingwanwq.com/2017/06/01/1649/ https://www.shuijingwanwq.com/2017/06/01/1649/#respond Thu, 01 Jun 2017 10:34:27 +0000 http://www.shuijingwanwq.com/?p=1649 浏览量: 198

1、重命名某个目录中的文件名,其代码,如图1

重命名某个目录中的文件名

图1

2、报错:rename(E:/wwwroot/avatar/BEIJI/侯森.jpg,E:/wwwroot/avatar/BEIJI/378477.jpg): ϵͳ�Ҳ���ָ�����ļ��� (code: 2),如图2

报错:rename(E:/wwwroot/avatar/BEIJI/侯森.jpg,E:/wwwroot/avatar/BEIJI/378477.jpg): ϵͳ�Ҳ���ָ�����ļ��� (code: 2)

图2

3、使用 file_exists 函数,检查文件是否存在,如果存在,打印1,如果不存在,打印0,如图3

使用 file_exists 函数,检查文件是否存在,如果存在,打印1,如果不存在,打印0

图3

4、打印结果为0,表示检查文件的结果为不存在,如图4

打印结果为0,表示检查文件的结果为不存在

图4

5、打开网址:http://php.net/manual/zh/function.rename.php ,发现一段提示:,用以解决此类问题,如图5
翻译:在windows(XP,vista,7 …)http://fr.wikipedia.org/wiki/Windows-1252“,如果你的文件名包含口音,它基本上不起作用,所以使用iconv函数从 utf-8到cp1252如下:

在windows(XP,vista,7 ...)http://fr.wikipedia.org/wiki/Windows-1252“,如果你的文件名包含口音,它基本上不起作用,所以使用iconv函数从 utf-8到cp1252如下:

图5

6、iconv — 字符串按要求的字符编码来转换,将字符串 E:/wwwroot/avatar/BEIJI/侯森.jpg 从 UTF-8 转换编码到 GB2312,代码,如图6

iconv — 字符串按要求的字符编码来转换,将字符串 E:/wwwroot/avatar/BEIJI/侯森.jpg 从 UTF-8 转换编码到 GB2312

图6

7、打印结果为1,表示检查文件的结果为存在,如图7

打印结果为1,表示检查文件的结果为存在

图7

8、最终实现代码,如图8

最终实现代码

图8

9、目录 E:/wwwroot/avatar/BEIJI 中的文件,如图9

目录 E:/wwwroot/avatar/BEIJI 中的文件

图9

10、运行脚本,目录 E:/wwwroot/avatar/BEIJI 中的文件,已经重命名成功,如图10

运行脚本,目录 E:/wwwroot/avatar/BEIJI 中的文件,已经重命名成功

图10

11、运行脚本,报错:iconv(): Detected an illegal character in input string,如图11
翻译:iconv():检测到输入字符串中存在非法字符

运行脚本,报错:iconv(): Detected an illegal character in input string

图11

12、打印文件名,发现非法字符应该为 吴䶮,如图12

打印文件名,发现非法字符应该为 吴䶮

图12

13、将 GB2312 修改为 GB18030(如果修改为GBK的话,仍然报错,GB18030字符集包含GBK字符集和中日韩(CJK) Ext-A ),如图13

将 GB2312 修改为 GB18030(如果修改为GBK的话,仍然报错,GB18030字符集包含GBK字符集和中日韩(CJK) Ext-A )

图13

]]>
https://www.shuijingwanwq.com/2017/06/01/1649/feed/ 0
FlashFXP上从CentOS 6.5下载中文名称文件失败的解决 https://www.shuijingwanwq.com/2015/11/11/749/ https://www.shuijingwanwq.com/2015/11/11/749/#respond Wed, 11 Nov 2015 08:41:03 +0000 http://www.shuijingwanwq.com/?p=749 浏览量: 63

1、FlashFXP上从CentOS 6.5下载中文名称文件失败,截图如下:

FlashFXP上从CentOS 6.5下载中文名称文件失败

FlashFXP上从CentOS 6.5下载中文名称文件失败

2、在站点管理器的选项中,设置字符编码为UTF-8

在站点管理器的选项中,设置字符编码为UTF-8

在站点管理器的选项中,设置字符编码为UTF-8

3、重新连接FTP站点之后,便可以成功下载中文名称文件

重新连接FTP站点之后,便可以成功下载中文名称文件

重新连接FTP站点之后,便可以成功下载中文名称文件

]]>
https://www.shuijingwanwq.com/2015/11/11/749/feed/ 0