Laravel项目gcloud app部署失败

时间:2018-03-06 09:56:46

标签: php laravel google-app-engine google-cloud-platform

将第一个幼虫项目部署到Google Cloud时遇到问题。

如果我的问题很愚蠢,请发表评论。我不是php开发人员,甚至不是web开发人员。我只是想测试一下并坚持这个问题超过1天。

我创建了一个带有小型数据库和几个CRUD restful api的幼虫项目。我在当地测试Postman,它工作正常。 所以我想上传到服务器,然后选择带有App Engine的Google云端存储。 我点了这个链接 - https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible

我可以通过拨打http://MY_PROJECT_ID.appspot.com

来查看laravel主屏幕

我通过调用我的get api http://MY_PROJECT_ID.appspot.com/users

来收到错误

所以我认为我需要设置数据库。我按照上面提到的链接"设置数据库会话" 进行操作。

之后我打电话给 gcloud app deploy --project [MY_PROJECT_ID]
然后我得到以下错误:

[06-Mar-2018 03:36:44 UTC] [2018-03-06 03:36:44] production.ERROR: SQLSTATE[HY000] [2002] No such file or directory {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []
Step #1: [06-Mar-2018 03:36:44 UTC] [2018-03-06 03:36:44] production.ERROR: SQLSTATE[HY000] [2002] No such file or directory (SQL: delete from `cache`) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory (SQL: delete from `cache`) at /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []
Step #1: 
Step #1: In Connection.php line 664:
Step #1:                                                                                
Step #1:   SQLSTATE[HY000] [2002] No such file or directory (SQL: delete from `cache`)  
Step #1:                                                                                
Step #1: 
Step #1: In PDOConnection.php line 47:
Step #1:                                                     
Step #1:   SQLSTATE[HY000] [2002] No such file or directory  
Step #1:                                                     
Step #1: 
Step #1: In PDOConnection.php line 43:
Step #1:                                                     
Step #1:   SQLSTATE[HY000] [2002] No such file or directory  
Step #1:                                                     
Step #1: 
Step #1: Script php artisan cache:clear handling the post-install-cmd event returned with error code 1
Step #1: The command '/bin/sh -c /build-scripts/composer.sh' returned a non-zero code: 1
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker@sha256:5ebcd6cbf6e0a0279e25f8a1c73ae87f7d601fbb86f29a34a82110bd81249722" failed: exit status 1

我甚至不知道哪一步是错的。错误日志显示错误在脚本 php artisan cache:clear 中,因此我单独调用此命令并且它运行良好。我能感觉到一些或许多事情都是错的。 我希望有人能指出我出了什么问题。

2 个答案:

答案 0 :(得分:0)

现在我可以通过替换:

成功部署
post-install-cmd": [
"chmod -R 755 bootstrap\/cache",
"php artisan cache:clear" ] 

"post-install-cmd": [
    "Illuminate\\Foundation\\ComposerScripts::postInstall",
    "php artisan optimize",
    "chmod -R 755 bootstrap\/cache" ]

在composer.json

但之后我又遇到了另一个问题。

答案 1 :(得分:0)

我解决了这个问题,在app.yaml文件中将CACHE_DRIVER的值从“database”更改为“file”。

当值设置为“database”并且gcloud app deploy函数运行php artisan cache:clear(在composer.json中表示为post-install-cmd)时,这将执行查询以删除“缓存“数据库上的表”。 但在我的情况下,我猜也是在你的情况下我们使用缓存文件而不是数据库表。

同样的问题和相同的解决方案适用于将SESSION_DRIVER值更改为“file”的会话。