Laravel 8.x deployed to Heroku, based on PostgreSQL implementation
1. In the local development environment, Laravel Sail has been deployed based on the deployment. Open URL:http://weibo.test/, the response 200. as shown in Figure 1
2. Register a Heroku account and use @163.com to find that it is not allowed, and finally use @gmail.com, the registration is successful. as shown in Figure 2
3. Click the link in the email address @gmail.com to activate the account. as shown in Figure 3
4. Reference URL:https://devcenter.heroku.com/articles/heroku-cli. The Heroku command line interface (CLI) makes it easy to create and manage Heroku applications directly from the terminal. This is an important part of using Heroku.
5. In the Ubuntu system in WSL2, run the following command from the terminal. Error: error: cannot communicate with server: posthttp://localhost/v2/snaps/heroku:dial unix /run/snapd.socket: connect: no such file or directory. as shown in Figure 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. Finally decided to use the software under Windows. Download the appropriate installer for your Windows installation. as shown in Figure 5
7. Error opening file for writing. as shown in Figure 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. Reinstall, run as administrator, no more errors.
9. Verify your installation. To verify your CLI installation, use the heroku –version command. has been successfully installed. as shown in Figure 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. After installing the CLI, run the heroku login command. You will be prompted to enter any key to go to the web browser to complete the login. Then the CLI will automatically let you log in. as shown in Figure 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. Reference URL:https://devcenter.heroku.com/articles/getting-started-with-php. Because the documentation assumes that PHP and Composer are installed locally. Since the PHP version of the local environment is inconsistent with the version in the Laravel Sail environment, it is decided to upgrade the PHP version of the local environment to PHP 8.1 first. As shown in Figure 9, Figure 10
The version number of the local environment:
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>
The version number of the Laravel Sail environment:
# 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. The PHP version of the upgraded local environment, 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. Go to the root directory of the program and use the heroku create command to create a new application on Heroku. secret-stream-72395 is the default name that Heroku randomly generated for the application, and the names generated by each person are not the same. buthttps://secret-stream-72395.herokuapp.com/It is the online address of the application. as shown in Figure 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. The Heroku platform supports multiple languages. When deploying the application, Heroku will automatically check what language the application code is written in, and then perform a series of operations for the language to prepare the program running environment. The Laravel application will contain the package.json file by default, but when Heroku checks the file, it will think that the application is written with Node.js, so we need to declare the buildpack of the application, telling Heroku said that our application was written in PHP. as shown in Figure 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. Push and deploy the code to Heroku. as shown in Figure 13
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 ..." 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>
16. The application is now deployed. Make sure that at least one application instance is running and now access the application via the URL generated by the application name. As a convenient shortcut, you can open the website as follows. Figure 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. However, the website is automatically opened in the browser:https://secret-stream-72395.herokuapp.com/, response 403. as shown in Figure 15
Forbidden
You don't have permission to access this resource.
18. Prompt in step 15: No ProcFile, usingWeb: heroku-php-apache2. Create a new ProcFile file under the Laravel project, and tell Heroku what command to use to start the web server by configuring the file. Then you need to include the file into Git version control. Error: push failed: cannot parse procfile.. as shown in Figure 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. View the content of the file Procfile, as shown in Figure 17
web:
vendor/bin/heroku-php-apache2
public/
20. Refer to Getting Started with Laravel on Heroku:https://devcenter.heroku.com/articles/getting-started-with-laravel. View the content of the file Procfile, as shown in Figure 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. Set the Laravel encryption key, and use the Artisan command that comes with Laravel to generate the App Key. as shown in Figure 19
PS E:\wwwroot\weibo> php artisan key:generate --show
base64:qtlcYLZF38gHDz/XhCE/cc0Q+BwByRygnVpfWwtRipA=
PS E:\wwwroot\weibo>
22. Based on the generated App Key, run the command line to complete the configuration. As shown in Figure 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. When pushing, still report an error: push failed: cannot parse procfile.
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 :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>
24. Save the file encoding as UTF-8 . as shown in Figure 21
25. The push is successful, and the URL is opened:https://secret-stream-72395.herokuapp.com/, the response 200. Figure 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. However, when submitting the form and writing data to MySQL, it responds to the 500 server error because the database does not exist. Figure 23
27. Use PostgreSQL on Heroku as the database we apply. Install the PostgreSQL extension. Heroku will generate a unique database URL – database_url for us, and we can view all the configuration information of Heroku through the command: Heroku config. Figure 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. In local development, we use mysql as the database storage, but in the heroku environment we need to use postgresql as the database storage. Therefore, when setting the database, we need to judge the current environment. If the environment is a local environment, the MySQL database is used, and if it is a Heroku environment, the PostgreSQL database is used. We can determine whether the application is running on Heroku by adding a new IS_IN_HEROKU configuration item to Heroku. Generally speaking, the application database is configured in config/database.php, so we need to define a help method for the database connection method of different environments for the configuration file, so that the database configuration information is specified according to the different running environments of the application, we need to create a new one helpers.php file and write the following:
'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', ''),
];
}
}
29. After adding the helpers.php file, you also need to add the file field to the Autoload option in the composer.json file in the root directory of the project. as shown in Figure 25
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/helpers.php"
]
},
30. After modifying and saving, run the following commands to reload the file. If it is possible to affect the running of the program in the local environment, it is recommended to execute the corresponding command in the Sail environment. Figure 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. Now, let’s configure the database using the just defined get_db_config method. Adjust the database profile, and the total is changed in two places. as shown in Figure 28
$db_config['connection'],
32. The changed code is submitted and pushed to GitHub and 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. We can use Heroku run to run the specified command of Laravel in Heroku. Now we need to perform migration on Heroku to generate user tables, which can be done through the following command, and an error is reported: sqlstate[22023]: Invalid parameter value: 7 error: invalid value for parameter “client_encoding”: “utf8mb4” . as shown in Figure 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. Adjust the database configuration file again. The previous pgsql-related configuration has not been modified.
'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. Execute the command: heroku config:add db_connection=pgsql . The error is different when performing the migration again:
» 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. Finally found the root cause of missing the addition of an IS_IN_HEROKU configuration item in Heroku to determine whether the application is running on Heroku. Migration was successful. as shown in Figure 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. Submit the form data again, and the submission is successful. as shown in Figure 30
38. Use heroku rename to change the application name, but make sure that the changed name is not occupied by others. as shown in Figure 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. Open:https://app-wangqiang-weibo.herokuapp.com/, the response 200. in line with expectations. Figure 32
40. Open:https://secret-stream-72395.herokuapp.com/, response 404. thereins nothing here, yet. in line with expectations. Figure 33



























![我们可以使用 heroku run 在 Heroku 运行 Laravel 的指定命令。现在我们需要在 Heroku 上执行迁移,生成用户表,可通过下面命令来完成,报错:SQLSTATE[22023]: Invalid parameter value: 7 ERROR: invalid value for parameter "client_encoding": "utf8mb4" 。](https://www.shuijingwanwq.com/wp-content/uploads/2021/12/28-1.png)




