Google App Engine .yaml file working locally but not when deployed - php

My GAE PHP .yaml file works locally but not when deployed. Everything worked fine up until I reorganized the folders my .php scripts were contained in. There is a php folder in the root of the app and the .php further organized into folders.
Current YAML file:
application: raven3mil
version: 1
runtime: php
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /images
static_dir: /static/images
# Serve php scripts.
- url: /(.+\.php)$
script: \1
- url: /.*
script: /login.php
error_handlers:
- file: /errors/404.html
File structure example:
+root
+php
+admin
manageUsers.php
+teacher
lessons.php
+student
schedule.php
dashboard.php
+css
index.css
main.css
+js
+jquery
+bootstrap
login.php
I'm not sure why my YAML file works locally but not deployed. Can anyone give any insight?

If your scripts are using content from static_dir's you need to make sure they are available to the application.
You can achieve that by adding application_readable: true to your js, css and images handlers.
You can read more about it here: https://cloud.google.com/appengine/docs/php/config/appconfig

Related

How to ignore directory of index.php in urlFor() link?

I'm using gcloud's app engine with my index.php file in in a directory called '/public'. I set the app.yaml file's entry point to start there, so it treats that folder like the root directory in the url.
When I manually code the links on my site (href="home") everything works great (link shows as mysiteurl.com/home). When I use href="{{ urlFor('home') }}" the link shows as mysiteurl.com/public/home.
All the links work, and the site runs without error, but I don't want the /public showing up in the links or url. Is there a way to set an "entry point" (like in gcloud) for slim/twig so it treats /public as the root directory when generating links?
Update: This may actually be a gcloud issue. On localhost everything works as expected (using an .htaccess file that is ignored in .gcloudignore) but when I deploy the app the links become /public/page. Maybe app.yaml entry point is causing the issue?
Addtl Info:
I'm using a standard environment and here is my app.yaml file:
runtime: php72
entrypoint: serve public/index.php
basic_scaling:
max_instances: 1
idle_timeout: 5m
handlers:
- url: /css
static_dir: public/css
- url: /data
static_dir: public/data
- url: /fonts
static_dir: public/fonts
- url: /img
static_dir: public/img
- url: /js
static_dir: public/js
- url: /libs
static_dir: public/libs
- url: /scss
static_dir: public/scss
- url: /.*
script: auto
secure: always

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.

How to get my application to work on appengine

I developed a web application the usual way and hosted on a normal shared server.
These are what I mean by usual
Include my PHP function files (using php include/require)
Use my normal MySQL database with msqli
Upload my files normally to the server using FTP.
For some reasons, I need to move the web app to appengine, I have succeeded in uploading the files but it shows me this error:
500 Server Error
with this error in my log:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
ImportError: No module named index
What changes do I need to make to my files to enable my website work well on appengine without issues?
EDIT (Content of app.yaml)
application: gcdc2013-myworkset
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: index.php
- url: /css
static_dir: stylesheets
- url: /images
static_dir: images
libraries:
- name: webapp2
version: "2.5.2"
I tried changing runtime to php but it gave an error which cleared immediately i changed it back to python27
EDIT:
Updated app.yaml file (Project deploys now but shows this error for all PHP files: Could not guess mimetype for excel/excel_reader.php. Using application/octet-stream.
Also the project appears as blank when viewed on the browser):
application: gcdc2013-myworkset
version: 1
runtime: php
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: index.php
- url: /
script: index.php
- url: /index\.php
script: index.php
- url: /features
script: features/index.php
- url: /about
script: about/index.php
- url: /oauth2callback/?
script: signup.php
- url: (.*)\.[\d]{10}\.(css|js)
static_files: $1.$2
upload: (.*).(.*)
- url: /css
static_dir: css
- url: /js
static_dir: js
Also, how can I import mysql database that I exported from my localhost to the appengine?
Change:
runtime: python27
To:
runtime: php
And remove:
libraries:
- name: webapp2
version: "2.5.2"
See https://developers.google.com/appengine/docs/php/config/appconfig for more information.

Categories