简体   繁体   中英

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. I can't seem to wrap my head around how to get my code onto Google App Engine. I went through the "hello world" PHP example. 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.

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?

Thank you.

App Engine is different than what you're used to with web hosting providers. When you deploy an your application to App Engine you aren't pushing files to a remote folder on a server. 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.

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.

You will also use gcloud app deploy to deploy your app rather than a tool like 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.

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. 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. After uploading your .php files follow the steps:

  1. Create app.yaml file for PHP in your folder where the .php files are stored.
  2. Connect to your 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
  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.
  5. After the deployment you can view your web app by using the command: gcloud app browse

    Paste this code in your app.yaml file

    runtime: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM