2

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
Community
  • 1
  • 1
Gas K.
  • 23
  • 5

2 Answers2

0

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
GAEfan
  • 11,244
  • 2
  • 17
  • 33
  • i just tried it and nothing happened :(...thank you for your response – Gas K. Dec 11 '16 at 22:09
  • i posted my index.php. :) – Gas K. Dec 11 '16 at 23:32
  • Are you sure this is deploying, and you are going to proper URL? – GAEfan Dec 12 '16 at 00:31
  • locally i think it is working but when i deploy it i have the issue i described. In a desperate need to fix it i changed my app.yaml file so if you want take a look again. is there any clear tutorial for handlers except google's? – Gas K. Dec 12 '16 at 14:08
  • finally after a lot of debugging the problem was the path and the some issues with the database...Still working although to deploy it on google app engine!!:) – Gas K. Dec 14 '16 at 01:34
0

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
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • i changed the handlers as you told me and locally works perfectly! (see my new app.yaml above). When i deploy it although i have the same error as i descriped....thanks for your respone! – Gas K. Dec 12 '16 at 16:07
  • Check the app's request logs in the developer console (https://console.cloud.google.com/logs), look for requests causing 404 errors - some other element referenced in your `index.php` may be missing. Other errors may also be relevant. – Dan Cornilescu Dec 12 '16 at 16:20
  • i saw my log file and it is messed up! i edit my question with something new if you want to take a look – Gas K. Dec 12 '16 at 18:30
  • From here on it's plain debugging your app code. I can't help much - I'm using python myself, not php. You may have some local paths somehow leaked into your app code as `C:/Users/xxx...` makes no sense on GAE. – Dan Cornilescu Dec 12 '16 at 18:40
  • finally after a lot of debugging the problem was the path and the some issues with the database...Still working although to deploy it on google app engine!!:) – Gas K. Dec 14 '16 at 01:34