Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud App Engine app.yaml php72 issue with routing

I have a core php website and this is my current configuration of app.yaml

runtime: php72

handlers:
# Serve a directory as a static resource.
- url: /assets
  static_dir: assets

- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /ckeditor
  static_dir: ckeditor

# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$

# add all script entries like this
- url: /login.php
  script: auto

# Serve your app through a front controller at index.php or public/index.php.
- url: .*
  script: auto

Issue with this configuration is that it keeps redirecting (302) to login page again and again.. and ending up with error Too Many Redirects.

What am I missing?

GAE Logs:

2019-01-18 17:10:07 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:10 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:13 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:16 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:19 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:22 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:25 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:32:26 default[20190118t225141]  "GET / HTTP/1.1" 302
2019-01-18 17:32:26 default[20190118t225141]  nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2019-01-18 17:32:30 default[20190118t225141]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:32:33 default[20190118t225141]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:54:59 default[20190118t230733]  "GET / HTTP/1.1" 302
2019-01-18 17:55:00 default[20190118t230733]  nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2019-01-18 17:55:02 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:05 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:07 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:09 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:11 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:29 default[20190118t230733]  "GET / HTTP/1.1" 302
2019-01-18 18:17:32 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:35 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:37 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:40 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
like image 858
Shreejibawa Avatar asked Dec 14 '22 13:12

Shreejibawa


1 Answers

It turns out that php72 doesn't support script execution directly for standard environment. Everything needs to go through custom FrontController. So I created one FrontController which handles basically all routes. Below is the code I put in index.php. It will handle all specified routes.

switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
    case '/':
        require 'login.php';
        break;
    case '/product.php';
        require 'product.php';
        break;
    default:
        break;
}

You can find examples for php72 for custom FrontController and for different frameworks here. https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine

Thank you everyone for all your efforts. Hope this helps lost souls like me.

like image 172
Shreejibawa Avatar answered Jan 12 '23 20:01

Shreejibawa