显示标签为“Google App Engine”的博文。显示所有博文
显示标签为“Google App Engine”的博文。显示所有博文

2016年4月13日星期三

谷歌GAE安装WordPress博客:创建Cloud SQL上传文件和绑定域名

谷歌GAE安装WordPress博客:创建Cloud SQL上传文件和绑定域名

免费空间   2013年06月20日 17:52  
谷歌GAE安装Wordpress:创建Cloud SQL上传文件和绑定域名
谷歌GAE,即Google App Engine,是谷歌公司旗下了一个云空间,这个空间一直提供着免费配额的服务,在国内的知晓度几乎没有哪个免费空间可以比肩,网上关于GAE空间教程非常多,用GAE搭建的博客、相册、网盘、论坛等都有不少。
GAE云空间自运行以来就不支持PHP,这不得不说对PHPer来说是一个硬伤,记得几年前还有人用程序在GAE上模拟了PHP运行环境,看得出不少人对GAE运行PHP的渴望。终于到了2013年5月,谷歌已经宣布Google App Engine开始支持PHP运行了。
目前GAE免费云空间运行PHP还没有全面开放使用,想要使用的朋友可以参考谷歌GAE空间支持运行PHP来申请使用,部落已经在前几天收到了GAE发来的GAE运行PHP审核通过的消息,前一天还看到有朋友在部落论坛上发了自己申请成功了GAE PHP
这里还不得不吐槽一下差不多与GAE PHP同时申请的中国版Windows Azure,至今都没有看到有人被审核通过使用的消息,只是在邮箱中收到一个申请已经受理的提醒。所以想要使用微软的“正宗”产品,还是去直接使用Windows Azure国际版吧。
本篇文章将分享如何成功在GAE空间上安装Wordpress博客,包括创建Cloud SQL数据库,修改Wordpress配置文件,上传文件到GAE空间上和绑定自己的域名到GAE上,并最终实现GAE安装Wordpress在国内的正常访问。
很多人对一些国外的大公司推出的免费空间情有独钟,除了好用、限制少以外,长久免费、稳定等特点这应该是最重要的原因,这里有一些优秀的免费PHP空间产品:
谷歌GAE安装Wordpress:创建Cloud SQL上传文件和绑定域名
一、GAE安装Wordpress前准备
1、GAE官网:
  • 1、官网首页:https://appengine.google.com/
  • 2、控制平台:https://cloud.google.com/console
  • 3、GAE PHP申请:谷歌GAE空间支持运行PHP
2、第一次用GAE的朋友,参考:Google App Engine注册绑域名安装博客程序GAE应用安装和使用教程,这两篇文章对了解本文的操作过程很有帮助。
3、下载App Engine PHP SDK,这个是用来上传PHP文件的。这里是App Engine PHP SDK下载地址。将其解压放在C盘中。
4、GAE运行Wordpress需要用到Cloud SQL,你需要进入“控制平台”去激活Cloud SQL,激活前还需要在控制平台里添加一张信用卡。
创建Cloud SQL
5、这个和在GCE中创建VPS是一样的,经过部落测试可以用财付通美国运通卡通过验证。
创建Cloud SQL使用财付通
6、然后是新建一个Cloud SQL。
Cloud SQL新的应用
7、填写一个应用ID即可,例如:freehao123,再点击右边的“确认”就可以创建一个Cloud SQL了。(点击放大)
Cloud SQL新建一个
8、如果不想用Cloud SQL,我们还可以用远程MysqL数据库来帮助Wordpress运行在GAE上。
二、创建GAE运行PHP环境
1、在C盘中新建一个文件夹命名为:freehao123,在文件夹中新建一个文件:app.yaml,复制粘贴以下内容保存。

application: myfreehao123
version: wp
runtime: php
api_version: 1

handlers:
- url: /(.*\.(htm$|html$|css$|js$))
  static_files: wordpress/\1
  upload: wordpress/(.*\.(htm$|html$|css$|js$))
  
- url: /wp-content/(.*\.(ico$|jpg$|png$|gif$))
  static_files: wordpress/wp-content/\1
  upload: wordpress/wp-content/(.*\.(ico$|jpg$|png$|gif$))
  
- url: /(.*\.(ico$|jpg$|png$|gif$))
  static_files: wordpress/\1
  upload: wordpress/(.*\.(ico$|jpg$|png$|gif$))
  
- url: /wp-admin/(.+)
  script: wordpress/wp-admin/\1
  secure: always
  
- url: /wp-admin/
  script: wordpress/wp-admin/index.php
  secure: always

- url: /wp-login.php
  script: wordpress/wp-login.php
  secure: always

- url: /wp-cron.php
  script: wordpress/wp-cron.php
  login: admin

- url: /xmlrpc.php
  script: wordpress/xmlrpc.php

- url: /(.+)?/?
  script: wordpress/index.php
2、记得要将第一行的application名称改成自己的。
GAE修改应用ID
3、再新建一个php.ini文件,复制粘贴以下内容:

google_app_engine.enable_functions = "php_sapi_name, gc_enabled"
4、最后新建一个cron.yaml文件,复制以下内容:

cron:
- description: wordpress cron tasks
  url: /wp-cron.php
  schedule: every 2 hours
三、修改Wordpress配置文件
1、下载最新版本的Wordpress到本地,这里是WordPress最新中文版下载地址
2、将下载下来的Wordpress压缩包解压,会得到一个Wordpress文件夹,将这个文件夹移动到刚刚创建好的freehao123文件夹中,请看我的:
GAE下载文件
3、进入Wordpress文件夹中,将wp-config-sample.php重命名为wp-config.php,请把数据库名称、用户名、密码、主机这四项替换成以下内容。

/** WordPress 数据库的名称 */
define('DB_NAME', 'wordpress_db');

/** MySQL 数据库用户名 */
define('DB_USER', 'wp_user');

/** MySQL 数据库密码 */
define('DB_PASSWORD', 'wp_password');

/** MySQL 主机 */
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
  define('DB_HOST', ':/cloudsql/myfreehao123:freehao123');
}else{
  define('DB_HOST', 'localhost');
}
4、注意:myfreehao123:freehao123中mfreehao123是我应用名称,freehao123是我创建Cloud SQL名称。
GAE修改配置文件
四、在Cloud SQL创建Wordpress数据库环境
1、上面我们已经创建了一个Cloud SQL,我们需要在Cloud SQL中创建数据库名称、用户名、密码。
2、最简单的在Cloud SQL中创建数据库信息是Google提供的Import功能,官方已经有了SQL文件:http://storage.googleapis.com/appengine-php/setup.sql
GAE导入文件
3、在Cloud Storage Path中填入gs://appengine-php/setup.sql,点击OK,我们的MysqL数据库就创建完成了。
GAE官方文件
五、上传Wordpress到GAE成功运行WP博客
1、App Engine PHP SDK下载解压后放在C盘中,freehao123文件夹也是放在C盘中,打开运行命令,执行以下命令:

cd google_appengine
appcfg.py update -R C:\freehao123/
2、C:\freehao123/是你存放在应用文件的绝对路径,你如果是放在别的地方,请自行修改,运行命令后会要求输入GAE账号和密码。
谷歌GAE要输入密码
3、如果你的Google账号设置了两步验证,会出现如下错误:

Use an application-specific password instead of your regular account password.
See http://www.google.com/support/accounts/bin/answer.py?answer=185833
However, now the recommended way to log in is using OAuth2. See

https://developers.google.com/appengine/docs/python/tools/uploadinganapp#oauth

4、到Google两步验证中新建一个应用的专用密码即可。
谷歌GAE专用密码
5、稍等一会儿,文件即会全部上传到GAE空间上,如果你连接不了GAE空间服务器,请挂上D理。
谷歌GAE上传文件
6、进入GAE给你的二级域名,需要挂上D理,就可以在GAE安装运行Wordpress了。
谷歌GAE开始安装WP
六、GAE绑定域名成功访问Wordpress
1、GAE空间用默认的二级域名是在国内无法访问的,但是我们用自己的域名绑定到GAE上就可以正常访问了,而且速度还非常快。
PS:2013年6月28日更新,最新的GAE空间绑定自己的域名方法请参考:新的GAE空间绑定域名方法:添加自定义域名作DNS解析
2、在Application Settings 中有域名设置,点击可以添加自己的域名。
谷歌GAE添加自己的域名
3、要想成功将域名绑定在GAE上,该域名必须是已经使用了Google Apps,没有的请在右边注册添加。
谷歌GAE注册一个账号
4、更加详细的绑定域名方法参考:这是我在GAE上绑定的自定义域名。
谷歌GAE绑定域名完成
七、GAE安装Wordpress小结
1、其实在GAE上安装Wordpress整个过程说起来会比较繁琐,这里部落将自己的配置的Wordpress文件打包给大家:WordPress For GAE下载
2、下载wordpress for gae压缩包下载下来,解压里面有freehao123文件夹,你需要修改的是app.yaml中的application名称、wp-config.php中的myfreehao123:freehao123。
谷歌GAE修改两项文件
3、将这两项替换成你自己的,然后再将整个文件夹上传到你的GAE空间中,就可以直接进入到第五步的GAE安装Wordpress了,整个过程就变得简单多了。
4、GAE空间安装运行Wordpress并绑定域名演示:http://gae.freehao123.info/,这是谷歌官方自己搭建的:http://gaeforphp-blog.appspot.com/
文章出自:免费资源部落 http://www.freehao123.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。

Google App Engine: Platform as a Service 谷歌应用程序引擎:平台即服务

Tools you know and love. Python, Java, PHP, Go and our MySQL compatible Cloud SQL.
Used by millions. Snapchat, Rovio, and Khan Academy run on Google App Engine.
Build and deploy. No worrying about DBAs, servers, sharding, and load balancers.
Scale. Auto scale to 7 billion requests per day.

你知道和你喜爱的工具。 Python, Java, PHP, Go 和我们的 MySQL ,并且兼容Cloud SQL.
被数以百万次使用。 Snapchat, Rovio, and Khan Academy run on Google App Engine.
构建和部署。 不用担心关于数据库管理员,服务器,分片和负载评分器。
规模。 Auto scale to 7 billion requests per day.每天70亿个请求上下波动。

Choose a language 
选择一个语言
Python
Java
PHP
Go

Try a popular framework like Bottle or Django in our playground, which contains examples of a few bare bones apps. Try some or all of them, then download and push any of these examples into production in 5 minutes. Follow the steps on this page.
在我们的应用平台上,尝试用像Bottle或Django一样的常用架构,其中包含一些大概的app应用的例子。尝试一部分或者所有的,然后下载并且用5分钟推动这些例子成为作品。按这页以下步骤:

Take a test drive in the Cloud Playground

驾驶在云平台上做一个测试

Flask
Copy of Flask web framework - 4768042181459968.zip  
Note this playground is public and may be modified by anyone. Don't place sensitive source code or data here.
注意,这个平台是公开的并且可能被任何人修改。不要在这儿放置敏感的资源代码或者数据。

Django
Copy of Django framework - 5893942088302592.zip  

Bottle
Copy of https---github.com-GoogleCloudPlatform-appengine-python-bottle-skeleton-tree-playground - 4619512548687872.zip  
If your app fails to load in the IFRAME below, try running your app in a separate window.
如果你在下面的内嵌框架加载app失败,尝试运行你的app在独立的窗口。


When you're done experimenting, you can download a copy of the project. You have two options:
当你完成实验,您可以下载项目的一个副本。你有两个选择:
  • Press ZIP to download the code you just edited. Unzip the downloaded file and note the new project-directory.
  • Use the git clone command to download a copy of the original files in the project. This will create a new project-directory. Make a note of it:
  • 按ZIP下载你刚刚编辑的代码,解压下载的文件,并且注意新 project-directory.
  • 使用git clone命令下载原始项目文件的副本。这将创建一个新的project-directory。记下它:
  • git clone --recursive https://github.com/GoogleCloudPlatform/appengine-python-flask-skeleton
Now you're ready to begin working locally. Follow the remaining steps on this page.
现在您已经准备好开始在本地工作。按照这个页面的剩余步骤。

Run locally

本地运行

Before you start:

  • You need to be running Python 2.7
  • You must install pip1.4 or later.
  • Download and unzip the Python SDK. This will create a sdk-directory named google_appengine. Make a note of its location, and add it to your PATH.
  • App Engine only uses libraries that are inside your project directory. If you downloaded the project as a zip file, it already contains all the needed libraries. If you cloned the original repository, install dependencies in the project's lib directory by running this command:
在你开始之前:
  • cd <project-directory>
    pip install -r requirements.txt -t lib
To run the downloaded project from your machine:
用你的机器运行下载的项目:
  • Start a local server for the project with the command:
  • 用这条命令启动一个本地服务器命令:
        dev_appserver.py <project-directory>

Deploy to Google Cloud Platform

部署到谷歌的云计算平台

You need to give your app a title and an application identifier. The title is displayed in the browser window when users access your app. The identifier is used to create the app's URL. App Engine URLs look like this: your-app-identifier.appspot.com.
你需要给你的应用一个标题和一个应用程序标示符。这个标题是当其他用户访问你的应用时,展示在浏览器窗口的。标示符是用于创建应用程序的URL的。App Engine URLs 看起来像这样:your-app-identifier.appspot.com

Name and create your app

命名并且创建你的应用程序

Go to appengine.google.com and create an application. (If you've already created a new project using the Google Cloud Console, you can skip this step. The project title and id are the same as an app title and id.)

访问 appengine.google.com并且创建一个应用程序。(如果你已经用谷歌云控制台创建了一个程序,你可以跳过这步。项目的标题、id号和应用的标题id号相同)

Deploy your app

部署应用程序

  • Use the appcfg command. Supply your application identifier for the -A argument:
  • 用appcfg命令。提供你的应用程序标示符作为-A的参数:
    appcfg.py --oauth2 -A <your-app-or-project-id> update <project-directory>
  • The --oauth2 flag is used to provide password-less login to your App Engine account. This is necessary to authenticate the user who's uploading code. The first time you use oauth2, a browser page will pop up telling you that Google App Engine appcfg would like to view and manage apps deployed on Google App Engine. Click Accept. Your machine now has an appcfg token that will be used for automatic verification when you run the appcfg command again.
  • --oauth2 标记被用于提供无密码登陆到你的App Engine账号。这是为了认证谁是上传代码的用户的需要。当您第一次使用oauth2,一个浏览器页面将弹窗告诉你Google App Engine appcfg想查看和管理部署在谷歌的App Engine的应用。点击接受。你的机器立刻获得一个appcfg的标记,当你再次运行appcfg命令时它将被用于自动验证。
  • Point your browser to https://<your-app-identifer>.appspot.com.
  • 将浏览器指向 https://<your-app-identifer>.appspot.com.

What next?

下一步做什么?


The logos associated with the programming languages above are the trademarks or registered trademarks of their respective owners.
与上面的编程语言相关的商标是其各自所有者的商标或注册商标。


Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under theApache 2.0 License. For details, see our Site Policies.
Last updated 二月 7, 2014.
除非另有说明,这个页面的内容和代码示例是在 Creative Commons Attribution 3.0 License Apache 2.0 License许可下的. 详情参见我们的网站政策.
最后更新时间,2014.03.06.

What Is Google App Engine?


What Is Google App Engine?

Google App Engine是什么?

Google App Engine is a Platform as a Service (PaaS) offering that lets you build and run applications on Google’s infrastructure. App Engine applications are easy to build, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers for you to maintain. You simply upload your application and it’s ready to go.
Google App Engine 是一个平台即服务(PaaS)的产品,它可以让你在谷歌的基础设施里构建和运行你的应用程序。App Engine应用程序易于构建,易于维护,并且能方便的根据你的流量和数据存储需求的变化扩展。使用App Engine,你不用维护服务器。你轻易的上传你的应用并且确定它能用。

The App Engine runtime environment

App Engine 运行环境

Google App Engine supports apps written in a variety of programming languages.
Google App Engine 支持各种各样的编程语言编写的应用程序。
  • Java: Using App Engine’s Java runtime environment, you can build your application using standard Java technologies.
  • Python: App Engine features a fast Python interpreter and standard Python libraries.
  • PHP: App Engine uses Google's Cloud Platform services under the hood when you call standard PHP functions.
  • Go: App Engine features a Go runtime environment that runs natively compiled Go code.

  • Java: 使用App Engine的Java运行环境时,你能使用标准的Java技术构建你的应用程序。
  • Python: App Engine包含一个快速的Python解析器和一个标准的Python库。
  • PHP: 当你调用标准的PHP函数时,App Engine 使用谷歌的云平台服务高级选项。
  • Go: App Engine提供Go的运行环境,本地编译运行代码。
Google App Engine makes it easy to build and deploy an application that runs reliably even under heavy load and with large amounts of data. It includes the following features:
Google App Engine可以轻松的构建和部署一个应用程序,它甚至能在重负载和大数据量下运行。它具有一下特点:
  • Persistent storage with queries, sorting, and transactions.
  • Automatic scaling and load balancing.
  • Asynchronous task queues for performing work outside the scope of a request.
  • Scheduled tasks for triggering events at specified times or regular intervals.
  • Integration with other Google cloud services and APIs.
  • 持久性存储与查询、排序和汇报。
  • 自动缩放负载平衡。
  • 异步队列来执行工作范围之外的请求。
  • 在指定的时间或者定期计划任务触发事件。
  • 整合其他的谷歌晕服务和API。
Applications run in a secure, sandboxed environment, allowing App Engine to distribute requests across multiple servers, and scaling servers to meet traffic demands. Your application runs within its own secure, reliable environment that is independent of the hardware, operating system, or physical location of the server. For a full list of features, see our Features page.
应用程序在一个安全的,沙盒环境中运行,允许应用程序引擎可以在多个服务器之间分配请求,并扩展服务器来满足交通需求。您的应用程序在其自己的安全,可靠的环境,是独立于硬件,操作系统或服务器的物理位置运行。对于一个完整的功能列表,请参阅我们的功能页面

The App Engine development environment

App Engine的开发环境

Software Development Kits (SDKs) for App Engine are available in all supported languages. Each SDK includes:
  • All of the APIs and libraries available to App Engine.
  • A simulated, secure sandbox environment, that emulates all of the App Engine services on your local computer.
  • Deployment tools that allow you to upload your application to the cloud and manage different versions of your application.
The SDK manages your application locally, while the Administration Console manages your application in production. The Administration Console uses a web-based interface to create new applications, configure domain names, change which version of your application is live, examine access and error logs, and much more.

软件开发工具包(SDK)的用于应用程序引擎,可在所有支持的语言。每个SDK包括:
  • 所有API并提供给应用程序引擎库。
  • 一个模拟,安全的沙箱环境中,模拟所有App Engine的服务,您的本地计算机上。
  • 部署工具,使您可以将应用程序上传到云和管理不同版本的应用程序。
该SDK本地管理您的应用程序,而管理控制台 管理您的应用程序在生产。管理控制台使用基于Web的界面来创建新的应用程序,配置域名,更改您的应用程序的版本是活的,检查访问和错误日志,等等。

Quotas and limits

配额和限制

App Engine gives you 1 GB of data storage and traffic for free, which can be increased by enabling paid applications. However, some features impose limits unrelated to quotas to protect the stability of the system. For more details on quotas, including how you can edit them to suit your needs, see the Quotas page.
应用程序引擎为您提供了1 GB的数据存储和通信的自由,这可以提高使支付应用。不过,有些功能强加无关的配额,以保护系统的稳定极限。有关配额,包括如何对其进行编辑,以满足您的需求更多详细信息,请参阅配额页。

To get started...

要开始...

  1. Download the SDK.
  2. Sign up for an account.
  3. Read the getting started information for your language.
  4. Check out the rest of the App Engine documentation.
Welcome to Google App Engine!

  1. 下载SDK
  2. 注册申请一个账号。
  3. 阅读入门信息,为您的语言。
  4. 退房的其余App Engine的文档
欢迎来到谷歌应用程序引擎!

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under theApache 2.0 License. For details, see our Site Policies.
Last updated 二月 5, 2014.