YAML Script Handelers - php

I have two files in root folder. ie. index.php and signup.php and the app.yaml looks like this,
application: testcboy
version: 1
runtime: php
api_version: 1
threadsafe: yes
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /img
static_dir: img
- url: /.*
script: index.php
Problem is, when the link of singup.php from the home page (index.php) is cliked, then only the url of address bar is changes but page remains the same home page(index.php).

Did you read the documentation?
- url: /signup.php
script: signup.php
- url: /.*
script: index.php
or if you have lots of scripts you want to route to you could use something like
- url: /(.*)\.php
script: \1.php
- url: /.*
script: index.php

Related

Can't access my PHP files trough Ajax on the App engine

I have deployed a PHP app on the App engine but all my Ajax calls to PHP files seems to be redirected to my index.php file. Sending me the whole index.php's generated HTML as response.
Accessing the file directly also load the index.php (https://[mybucket].appspot.com/includes/engine/checkFollowStateFirestore.php)
I believe it may come from my App.yaml but i can't find a working answer on internet.
Here is my App.yaml file:
runtime: php72
default_expiration: "1s"
handlers:
- url: /css
static_dir: css
- url: /vendor/twbs/bootstrap/dist/css
static_dir: vendor/twbs/bootstrap/dist/css
- url: /js
static_dir: js
- url: /vendor/twbs/bootstrap/dist/js
static_dir: vendor/twbs/bootstrap/dist/js
- url: /assets/images
static_dir: assets/images
I have tried adding:
- url: .*
script: auto
or
- url: /includes/engine/*
script: auto
or
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
Options such as:
- url: /includes/engine/checkFollowStateFirestore.php
script: includes/engine/checkFollowStateFirestore.php
Gives me this error on deployment:
ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: script field for handler '/includes/engine/checkFollowStateFirestore.php' must be set to 'auto' for runtime php72
Using PHP include/require works.
Thanks a lot.

How should I write my app.yaml for my php app deployed to gcp's app engine?

I'm deploying a php app to GCP's app engine and can't make the app.yaml configuration work.
The app has this directory structure:
index.php
/sistema
/js
/images
/css
index.php
login.php
otherpage.php
...
I'm having problems with the pages that are under the 'sistemas' folder. And also would like to access those pages without the '.php' in the url.
I've tried with many handlers, but none of them worked as I wanted.
runtime: php55
threadsafe: yes
api_version: 1
handlers:
- url: /sistema/css/*
static_dir: sistema/css
- url: /sistema/js/*
static_dir: sistema/js
- url: /sistema/fonts/*
static_dir: sistema/fonts
- url: /sistema/images/*
static_dir: sistema/images
# Serve php scripts.
- url: /(.+\.php)$
script: \1
- url: /
script: index.php

configuring app.yaml for Google AppEngine to serve ajax requests for PHP

I've a simple folder structure,
main
|__core
|__start.php
|__bootstrap.php
js
|__file.js
css
|__file.css
index.php
Now, this file.js makes xhr request to start.php for which I'm getting a 500 error.
This is my app.yaml:
runtime: php55
api_version: 1
handlers:
- url: /
script: index.php
- url: /js
static_dir: js
- url: /css
static_dir: css
Now I'm not sure if I'm also suppose to do this:
- url: /main/core/.*
script: start.php
Which, by the way, doesn't seem entirely legit to me.

Removing PHP file extension when serving PHP files

I'm trying to remove the file extension in the address from all *.php files in my site. For instance, if a user visits mysite.com/about.php I want the URL to read mysite.com/about.
Here's my app.yaml:
application: mysite
version: 1
runtime: php55
api_version: 1
handlers:
# Static files
- url: /images/*
static_dir: images
- url: /css/*
static_dir: css
- url: /js/*
static_dir: js
# Routing
- url: /services(.*)
script: services.php
- url: /portfolio(.*)
script: portfolio.php
- url: /project(.*)
script: project.php
- url: /about(.*)
script: about.php
- url: /contact(.*)
script: contact.php
- url: /(.*)
script: index.php
How could I achieve this within GAE?
If all you need to do is perform that type of routing, you could use this:
application: mysite
version: 1
runtime: php55
api_version: 1
handlers:
# Static files
- url: /images/*
static_dir: images
- url: /css/*
static_dir: css
- url: /js/*
static_dir: js
# Special case, route requests for the root document
- url: /
script: /index.php
# If the request ends in [something].php, route to that file directly
- url: /(.+\.php)$
script: /\1
# Map all other requests to scripts of the same name
# so that, eg, /thispage (or /thispage/) routes to /thispage.php
- url: /(.*?)/?$
script: /\1.php
NB however that using this method you won't be able to handle 404 errors (although they don't appear to be handled in the app.yaml provided in the question either). Error-handlers in your app.yaml won't work for a 404 because they'll only kick in if they can't match any route you've provided.
So, if you want to handle 404 errors and such, what you should do instead is do the routing from inside a php script, like this:
-url: /(.*)
script: /routes.php
and inside routes.php inspect the $_SERVER['REQUEST_URI'] variable to see what page was requested, and serve the appropriate content accordingly.
edit: thanks to #Avinash Raj for cleaning up the regex Here

Google App Engine app has no links working

I am using Google App Engine for the first time. I am trying to upload a CodeIgniter website, but the problem is no links in the website is working. Every link, even the css and js are going to the index page.
Here is my app.yaml:
application: vatiali-dev
version: 1
runtime: php
api_version: 1
threadsafe: false
handlers:
- url: /css
static_dir: css/
- url: /js
static_dir: js/
- url: /fonts
static_dir: fonts/
- url: /.*
script: index.php
You should change your app.yaml to look like this:
application: vatiali-dev
version: 1
runtime: php
api_version: 1
threadsafe: true
handlers:
- url: /css/*
static_dir: css
- url: /js/*
static_dir: js
- url: /fonts/*
static_dir: fonts
- url: /.*
script: index.php
I have also changed threadsafe to true, unless you had it set to false for a specific reason I believe it is best practice/standard to set it to true, or else you may get performance issues.

Categories