简体   繁体   English

如何将我的PHP应用程序部署到Google App Engine?

[英]How to deploy my PHP application to Google App Engine?

I have always developed PHP locally on my machine, then uploaded to a web server via FTP. 我一直在计算机上本地开发PHP,然后通过FTP上传到Web服务器。 I can't seem to wrap my head around how to get my code onto Google App Engine. 我似乎无法全神贯注于如何将代码导入Google App Engine。 I went through the "hello world" PHP example. 我介绍了“ hello world” PHP示例。 Following their instructions, it seems to work fine in the end, but I am at a loss as to how to apply those steps to my own app. 按照他们的指示,它似乎最终效果很好,但是我对如何将这些步骤应用于自己的应用程序感到困惑。 I simply don't understand what is happening through the deploy process using Google Cloud SDK. 我只是不了解使用Google Cloud SDK进行的部署过程中发生了什么。

Can anyone offer a simple step by step example that explains how this seemingly simple task can be accomplished? 谁能提供一个简单的分步示例来说明如何完成看似简单的任务?

Is there a way to use good ole' FTP? 有没有办法使用优质的FTP?

Thank you. 谢谢。

App Engine is different than what you're used to with web hosting providers. App Engine与您使用网络托管提供商所使用的不同。 When you deploy an your application to App Engine you aren't pushing files to a remote folder on a server. 将应用程序部署到App Engine时,并不是将文件推送到服务器上的远程文件夹。 You're effectively packaging them into a container that App Engine can use that container to serve possibly many instances of your app so that it can handle automatically scaling your app up and down and many other aspects. 您正在将它们有效地包装到一个容器中,App Engine可以使用该容器来服务您的应用程序的许多实例,以便它可以自动处理应用程序的上下缩放以及许多其他方面。

Your application is configured via the app.yaml file where you register things like your URL handlers and how those map to individual PHP files. 通过app.yaml文件配置应用程序,在其中注册URL处理程序之类的内容,以及它们如何映射到单个PHP文件。

You will also use gcloud app deploy to deploy your app rather than a tool like FTP. 您还将使用gcloud app deploy而不是FTP之类的工具来部署您的应用。 One nice thing about this, is that you can deploy multiple versions of your site simultaneously. 一件好事是,您可以同时部署网站的多个版本。 You can do pretty cool stuff with that like rolling back your site to a previous version if the latest version is "bad" or you can do traffic splitting to send some percentage of users to one version and the rest to another version. 您可以做一些很酷的事情,例如,如果最新版本为“不良”,则将站点回滚到以前的版本,或者可以进行流量拆分,以将一定比例的用户发送到一个版本,将其余用户发送到另一个版本。 You can use that functionality to A/B test aspects of your application to maybe see which version performs better with users. 您可以使用该功能对应用程序的各个方面进行A / B测试,以查看哪个版本的用户效果更好。

Overall, App Engine does require a bit of a shift in thinking from your standard hosting set up, but its a lot more powerful with less of an administrative burden on you. 总体而言,App Engine确实需要从标准托管设置中转变思路,但是它的功能要强大得多,而您的管理负担却更少。 And for small sites it has a free tier instead of spending money with a standard hosting provider. 对于小型网站,它具有免费套餐,而不是与标准托管服务提供商一起花钱。

If you have already created your .php files then start the google cloud shell, open the text editor, create a new folder inside the root directory and upload your .php files into that folder. 如果您已经创建了.php文件,请启动google cloud shell,打开文本编辑器,在根目录下创建一个新文件夹,然后将.php文件上传到该文件夹​​中。 After uploading your .php files follow the steps: 上传您的.php文件后,请按照以下步骤操作:

  1. Create app.yaml file for PHP in your folder where the .php files are stored. 在存储.php文件的文件夹中为PHP创建app.yaml文件。
  2. Connect to your google cloud shell. 连接到您的Google Cloud Shell。
  3. Enter into the folder where you have saved your files. 输入保存文件的文件夹。 For example if web is the name of the folder that you have created then simply enter the command: cd web 例如,如果web是您创建的文件夹的名称,则只需输入命令:cd web
  4. Now its time for you to deploy the web application so enter the command: gcloud app deploy, after that it will give you two options y/n then enter y to continue OR n to abort the deployment process. 现在是您部署Web应用程序的时候了,因此输入命令:gcloud app deploy,之后它将为您提供两个选项y / n,然后输入y继续,或者输入n放弃部署过程。
  5. After the deployment you can view your web app by using the command: gcloud app browse 部署后,您可以使用以下命令查看您的Web应用程序:gcloud app browser

    Paste this code in your app.yaml file 将此代码粘贴到您的app.yaml文件中

    runtime: php55 api_version: 1 运行时:php55 api_version:1

handlers: 处理程序:

- url: /(.+\.(ico|jpg|png|gif))$
  static_files: \1
  upload: (.+\.(ico|jpg|png|gif))$
  application_readable: true

- url: /(.+\.(htm|html|css|js))$
  static_files: \1
  upload: (.+\.(htm|html|css|js))$
  application_readable: true

- url: /(.+\.php)$
  script: \1


- url: /.*
  script: index.php

and that's how you deploy your PHP web application in Google App Engine. 这就是您在Google App Engine中部署PHP Web应用程序的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将php应用程序从本地计算机部署到Google App Engine - How to deploy a php application from local machine to google app engine 如何在不运行Composer的情况下在Google App Engine上部署php应用程序? - How to deploy a php application on Google App Engine without them running composer? 如何使用谷歌应用引擎将 php 项目部署到谷歌云中? - How to deploy php project into google cloud using google app engine? 当我尝试将PHP应用程序部署到Google App Engine时,为什么突然出现400错误? - When I try to deploy my PHP application to Google App Engine, why am I suddenly getting a 400 error? 如何在 Google APP Engine 中部署 PHP 和 .htaccess 中的项目? - How to deploy a project made in PHP with .htaccess in Google APP Engine? 如何查看文件部署到Google App Engine的php应用程序 - How to view files a php application deployed to google app engine 如何在PHP和Google Cloud Platform上部署PHP应用程序? - How can I deploy my PHP application on Google cloud Platform? 如何在我的脚本/自动加载中包含Google App Engine for PHP? - How to include Google App Engine for PHP in my scripts / autoloading? 如何在 GAE [Google App 引擎] PHP 上创建或部署另一个服务/模块(默认已部署) - How to create or deploy another service/module (have deployed on default) on GAE [Google App engine] PHP Google App Engine部署失败 - google app engine deploy fail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM