PHP GAE的Yaml结构

时间:2016-12-11 21:06:05

标签: php google-app-engine yaml

我是使用GAE进行开发的新手,当我在云中部署应用程序时,我遇到了一个问题。

>错误:未找到此服务器上未找到请求的URL。

我的app.yaml文件是

application: xxxx
version: 3
runtime: php55
api_version: 1
threadsafe: yes

env_variables:
  # Replace project, instance, database, user and password with the values obtained
  # when configuring your Cloud SQL instance.
  MYSQL_DSN: mysql:unix_socket=/cloudsql/xxxxx
  MYSQL_USER: xxx
  MYSQL_PASSWORD: 'xxxx'

handlers:

- url: /admin/js
  static_dir: admin/js

- url: /js
  static_dir: js

- url: /fonts/(.*\.otf)
  static_dir: fonts/\1
  mime_type: application/x-font-otf

- url: /css
  static_dir: css

- url: /admin/css
  static_dir: admin/css

- url: /admin/font-awesome
  static_dir: admin/font-awesome/\1
  mime_type: application/x-font-otf

- url: /admin/fonts
  static_dir: admin/fonts
  mime_type: application/x-font-otf

- url: /admin/images
  static_dir: admin/images

- url: /includes/js
  static_dir: /includes/js

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

- url: /.*
  script: index.php

我的文件结构是,这就是我想要成功的

image with structure

我关注了this主题。

我的Index.php代码

<?php require_once("admin/includes/Db_object.php") ?>
<?php require_once("admin/includes/init.php")?>
<?php include("includes/header.php"); ?>

<?php $photos = Photo::find_all();?>

<div class="row">

   <!-- Blog Entries Column -->
   <div class="col-md-12">
     <div class="thumbnails row">
       <?php  foreach ($photos as $photo): ?>
          <div class="col-md-4">
            <a class = "thumbnail" href="#" data-toggle="lightbox" >
            <img class="img-responsive home_page_photo" src="admin/<?php echo $photo->picture_path();?>" alt="" ></a>
            </div>
            <?php endforeach;?>
         </div>
       </div>
<!-- /.row -->
<?php include("includes/footer.php"); ?>

编辑:当我部署它时,这是我的日志文件中的错误

PHP Warning:  require_once(C:/Users/xxx/Desktop/MyGallery/admin/includes/new_config.php): failed to open stream: No such file or directory in /base/data/home/apps/s~my-project-test-150523/1.397682853077463759/admin/includes/init.php on line 10
18:30:31.878
PHP Fatal error:  require_once(): Failed opening required 'C:/Users/xxx/Desktop/MyGallery/admin/includes/new_config.php' (include_path='.;/base/data/home/apps/s~my-project-test-150523/1.397682853077463759/;/base/data/home/runtimes/php/sdk') in /base/data/home/apps/s~my-project-test-150523/1.397682853077463759/admin/includes/init.php on line 10

2 个答案:

答案 0 :(得分:0)

将最后一个处理程序更改为:

- url: /.*
  script: index.php

将上述处理程序中未找到的任何请求发送到index.php。或者,为了更多控制:

- url: /
  script: index.php

- url: /.*
  script: not_found.php

答案 1 :(得分:0)

您需要删除以下/文件路径中的前导script

- url: /footer.php
  script: /includes/footer.php

- url: /header.php
  script: /includes/header.php

- url: /navigation.php
  script: /includes/navigation.php

- url: /sidebar.php
  script: /includes/sidebar.php

还要检查其他拼写错误,例如:

- url: /admin/edit_photo.php
  script: admin/dit_photo.php

使用通用的.php脚本处理程序会不会更容易?与文档Example中显示的一样:

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

旁注:为什么你甚至懒得尝试翻译/缩短某些脚本路径(并且由于在过程中污染app.yaml文件内容而导致错误的风险很大)当你实际上没有使用较短的路径时版本,例如在index.php

<?php require_once("admin/includes/Db_object.php") ?>
<?php require_once("admin/includes/init.php")?>
<?php include("includes/header.php"); ?>

如果删除路径的转换/缩短,那么上面的通用处理程序也会覆盖它们。更清洁(更安全)。

<强>更新

清洁工app.yaml允许发现其他一些可能出现的问题(我不确定他们是否确实造成了麻烦)。

您似乎尝试使用带有static_dir配置的正则表达式分组,例如:

- url: /fonts/(.*\.otf)
  static_dir: fonts/\1
  mime_type: application/x-font-otf

根据Handlers element表中的相应行,只有static_files个配置可以使用此类分组。也许你在两个配置之间切换并忘了删除分组?

同样在一种情况下,您在相应的\1配置中引用了分组(url)但没有分组定义:

- url: /admin/font-awesome
  static_dir: admin/font-awesome/\1
  mime_type: application/x-font-otf