Yaml structure for PHP GAE

2 views
Skip to first unread message

Gas K. via StackOverflow

unread,
Dec 11, 2016, 4:11:08 PM12/11/16
to google-appengin...@googlegroups.com

I am new in developing with GAE and i am facing a problem when I deploy the app in cloud.

> Error: Not Found The requested URL / was not found on this server.

My app.yaml file is

application: the id of my project
version: 2
runtime: php55
api_version: 1
threadsafe: yes

handlers:

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

- 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: /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: /Database.php
  script: admin/includes/Database.php

- url: /Db_object.php
  script: admin/includes/Db_object.php

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

- url: /function.php
  script: admin/includes/function.php

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

- url: /init.php
  script: admin/includes/init.php

- url: /new_config.php
  script: admin/includes/new_config.php

- url: /page_content.php
  script: admin/includes/page_content.php

- url: /session.php
  script: admin/includes/session.php

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

- url: /top_nav.php
  script: admin/includes/top_nav.php

- url: /User.php
  script: admin/includes/User.php

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

- url: /comments.php
  script: admin/comments.php

- url: /create_user.php
  script: admin/create_user.php

- url: /delete_photo.php
  script: admin/delete_photo.php

- url: /delete_user.php
  script: admin/delete_user.php

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

- url: /edit_user.php
  script: admin/edit_user.php

- url: /index.php
  script: admin/index.php

- url: /index_photo.php
  script: admin/index_photo.php

- url: /login.php
  script: admin/login.php

- url: /logout.php
  script: admin/logout.php

- url: /photos.php
  script: admin/photos.php

- url: /upload.php
  script: admin/upload.php

- url: /users.php
  script: admin/users.php

- url: .*
  script: index.php

The structure of my files is and this is what i am trying to succeed

image with structure

PS:i followed this topic How to construct a app.yaml file? and i had a lot of searching but nothing worked.

thank you!



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41091146/yaml-structure-for-php-gae

Gas K. via StackOverflow

unread,
Dec 11, 2016, 4:21:04 PM12/11/16
to google-appengin...@googlegroups.com

image with structure

Gas K. via StackOverflow

unread,
Dec 11, 2016, 4:26:05 PM12/11/16
to google-appengin...@googlegroups.com

I am new in developing with GAE and I am facing a problem when I deploy the app in cloud.

I followed this topic.

GAEfan via StackOverflow

unread,
Dec 11, 2016, 4:46:05 PM12/11/16
to google-appengin...@googlegroups.com

Change the last handler to:

- url: /.*
  script: index.php

That sends any request not found in the handlers above to index.php. Or, for more control:

- url: /
  script: index.php

- url: /.*
  script: not_found.php


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41091146/yaml-structure-for-php-gae/41091435#41091435

Gas K. via StackOverflow

unread,
Dec 11, 2016, 6:41:05 PM12/11/16
to google-appengin...@googlegroups.com

my Index.php code

<?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"); ?>

Gas K. via StackOverflow

unread,
Dec 12, 2016, 9:11:07 AM12/12/16
to google-appengin...@googlegroups.com

I am new in developing with GAE and I am facing a problem when I deploy the app in cloud.

> Error: Not Found The requested URL / was not found on this server.

My app.yaml file is

application: xxxxx
version: 2
runtime: php55
api_version: 1
threadsafe: yes

handlers:

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

- 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: /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: /admin/Database.php
  script: admin/includes/Database.php

- url: /admin/Db_object.php
  script: admin/includes/Db_object.php

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

- url: /admin/function.php
  script: admin/includes/function.php

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

- url: /admin/init.php
  script: admin/includes/init.php

- url: /admin/new_config.php
  script: admin/includes/new_config.php

- url: /admin/page_content.php
  script: admin/includes/page_content.php

- url: /admin/session.php
  script: admin/includes/session.php

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

- url: /admin/top_nav.php
  script: admin/includes/top_nav.php

- url: /admin/User.php
  script: admin/includes/User.php

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

- url: /admin/comments.php
  script: admin/comments.php

- url: /admin/create_user.php
  script: admin/create_user.php

- url: /admin/delete_photo.php
  script: admin/delete_photo.php

- url: /admin/delete_user.php
  script: admin/delete_user.php

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

- url: /admin/edit_user.php
  script: admin/edit_user.php

- url: /admin/index.php
  script: admin/index.php

- url: /admin/index_photo.php
  script: admin/index_photo.php

- url: /admin/login.php
  script: admin/login.php

- url: /admin/logout.php
  script: admin/logout.php

- url: /admin/photos.php
  script: admin/photos.php

- url: /admin/upload.php
  script: admin/upload.php

- url: /admin/users.php
  script: admin/users.php

- url: .*
  script: index.php

Dan Cornilescu via StackOverflow

unread,
Dec 12, 2016, 9:51:05 AM12/12/16
to google-appengin...@googlegroups.com

You need to remove the leading / in the following script file paths:

- 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

Also check for other typos, like this one:

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

Wouldn't it be easier to just use a generic .php script handler? Like the one shown in the documentation Example:

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

Side note: why do you even bother trying to translate/shorten some of the script paths (and greatly risking errors due to polluting the app.yaml file content in the process) when you're not actually using the shorter versions, for example in your index.php:

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

If you drop the translation/shortening of the path then the above generic handler would cover them as well. Much cleaner (and safer).



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41091146/yaml-structure-for-php-gae/41103485#41103485

Gas K. via StackOverflow

unread,
Dec 12, 2016, 11:21:04 AM12/12/16
to google-appengin...@googlegroups.com

I am new in developing with GAE and I am facing a problem when I deploy the app in cloud.

> Error: Not Found The requested URL / was not found on this server.

My app.yaml file is

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

The structure of my files is and this is what i am trying to succeed

image with structure

I followed this topic.

my Index.php code

<?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"); ?>

Dan Cornilescu via StackOverflow

unread,
Dec 12, 2016, 11:51:07 AM12/12/16
to google-appengin...@googlegroups.com

You need to remove the leading / in the following script file paths:

- 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

Also check for other typos, like this one:

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

Wouldn't it be easier to just use a generic .php script handler? Like the one shown in the documentation Example:

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

Side note: why do you even bother trying to translate/shorten some of the script paths (and greatly risking errors due to polluting the app.yaml file content in the process) when you're not actually using the shorter versions, for example in your index.php:

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

If you drop the translation/shortening of the path then the above generic handler would cover them as well. Much cleaner (and safer).

Update:

The cleaner app.yaml allowed spotting some other possible problems (I'm not sure if they actually do cause trouble or not).

It seems you have attempts to use regular expression groupings with static_dir configs, for example:

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

According to the respective rows in the Handlers element table, only static_files configs can use such groupings. Maybe you switched between the 2 configs and forgot to remove the groupings?

Also in one case you have a reference to a grouping (\1) in but no grouping definition in the corresponding url config:

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


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41091146/yaml-structure-for-php-gae/41103485#41103485

Gas K. via StackOverflow

unread,
Dec 12, 2016, 1:41:04 PM12/12/16
to google-appengin...@googlegroups.com

I am new in developing with GAE and I am facing a problem when I deploy the app in cloud.

> Error: Not Found The requested URL / was not found on this server.

My app.yaml file is

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

The structure of my files is and this is what i am trying to succeed

image with structure

I followed this topic.

my Index.php code

<?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"); ?>

EDIT: this is an error from my log file when i deploy it

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
Reply all
Reply to author
Forward
0 new messages