Could not show images in Google App Engine - php

Could not show images in Google App Engine
My need is deploy some png images to GAE. i have tried with these two codes in app.yaml. But the webpage does not show the png images
- url: /(.*\.(gif|png|jpg|ico|jpeg))
static_files: \1
upload: (.*\.(gif|png|jpg|ico|js|css|jpeg))
- url: /(.*\.(gif|png|jpg|ico|jpeg))
static_files: /\1
upload: /(.*\.(gif|png|jpg|ico|js|css|jpeg))
my current app.yaml file content
api_version: 1
threadsafe: yes
runtime: php
application: samplesite
version: 1
handlers:
- url: /
script: index.php
- url: /(.+\.php)$
script: \1
- url: /(.*\.(gif|png|jpg|ico|jpeg))
static_files: \1
upload: (.*\.(gif|png|jpg|ico|js|css|jpeg))

Move your root handler to the bottom. It is overriding all the other entries below it.
Many also place static files under a particular directory in their source so they are easily managed.
# All URLs ending in .gif .png or .jpg are treated as paths to static files in
# the static/ directory. The URL pattern is a regexp, with a grouping that is
# inserted into the path to the file.
- url: /(.*\.(gif|png|jpg))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg)$

Related

YAML rendering index.html every time any PHP is called on gCloud App Engine

I am learning how to move my existing PHP project to gCloud.
For the same, I created an AppEngine project and have placed my code there.
Everything seems to work except the PHP files.
When I launch my project, the index files launches (as specified in app.yaml) and then where the PHP should execute, it's renders the index.html file. This creates a deadly loop of index calling PHP calling index calling PHP :(
I am sure I have my app.yaml wrong, but am unable to figure out where the problem is.
My yaml looks like this:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /dialpad_research/(.*\.(appcache|manifest))
mime_type: text/cache-manifest
static_files: dialpad_research/static/\1
upload: dialpad_research/static/(.*\.(appcache|manifest))
- url: /dialpad_research/static
static_dir: dialpad_research/static
# image files
- url: /dialpad_research/static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: static/\1
upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
# dialpad root
- url: /dialpad_research.*
static_files: dialpad_research/static/index.html
upload: dialpad_research/static/index.html
- url: /dialpad_research/api/(.+\.php)$
script: api/\1
Any help is appreciated.
Folder structure is like this:
Root
|
---- app.yaml
---- dialpad_research (folder)
|
---- static (folder with index file)
---- api (folder with PHP files)
You have to be careful with your regex matching. This url pattern:
- url: /dialpad_research/static
will match:
- url: /dialpad_research/static(anything to follow)
So, it will never get to the handler below:
- url: /dialpad_research/static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
Same for:
- url: /dialpad_research.*
After that, it can never get to:
- url: /dialpad_research/api/(.+\.php)$
Reorder your handlers so that they don't short-circuit.
Next, /api/ and /static/ are not at the root so your paths to them are incorrect. See below:
handlers:
- url: /dialpad_research/(.*\.(appcache|manifest))
mime_type: text/cache-manifest
static_files: dialpad_research/static/\1
upload: dialpad_research/static/(.*\.(appcache|manifest))
# image files
- url: /dialpad_research/static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: dialpad_research/static/\1
upload: dialpad_research/static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
- url: /dialpad_research/api/(.+\.php)$
script: dialpad_research/api/\1
- url: /dialpad_research/static
static_dir: dialpad_research/static
# dialpad root
- url: /dialpad_research.*
static_files: dialpad_research/static/index.html
upload: dialpad_research/static/index.html

I deploy static files (html,css, js) and working good at gae but for php files gives 404 error

My app.yaml as:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
as seen above static files are under www dir. and php files are under the vendor dir and its sub sirs. I have read all days doc. to understand this yaml file to able to understand but unfortunately not yet :) . So, html and all static files works perfect. but when ajax calls php with sending data to php. gives 404 error. It works good on local wamp server. main opening page is index.html under www . And its ok. All day I tested many variant to able to deploy php files. Not able yet.
mainProjectRoot>app.yaml ( only this file and two directory "www and vendor")
www/index.html
/css
/js
vendor/smsgonder.php
/mail.php
/../../more php files
At least I gave up to try more variant and I need help to set up app.yaml page. (except above variant all extra code I received always error and no deployment)
Any help will be much appretiated. Thanks in advance !
final app.yaml is
runtime: php55
api_version: 2
threadsafe: true
handlers:
- url: /(.+\.php)$
script: vendor/\1
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
EDIT
this is final app.yaml ... (for a while I have deployed php files and some are were woring . But again for some php I receive "POST 500 error "
in case I like to share final app.yaml file here.
runtime: php55
api_version: 2
threadsafe: true
handlers:
- url: /(.*).php
script: \1.php
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
Any help will be very much appreciated. How could be :)) I spent 5-6 days just for deploying finished app :)'
add this immediately after handlers:
- url: /(.*)\.php$
script: vendor/\1.php
This will serve all request ending with .php to the php files within the vendor folder
The handlers section for PHP scripts following the documentation Example (works for vendor subdirectories as well):
# Serve php scripts.
- url: /(.+\.php)$
script: \1
Note: indentation matters!

Error [13] in deploying App Engine Application using Jenkins and gcloud

I am trying to deploy a mediawiki application to app engine using Jenkins as described in Google's push to deploy method https://cloud.google.com/tools/cloud-repositories/docs/push-to-deploy.
I am deploying mediawiki based on the same configurations here: https://github.com/tyolab/mediawiki-on-gae.
Some times I deploy the app and it is a success, but many times it fails with the following error:
Updating module [default].../
Updating module [default]...-
Updating module [default]...\
Updating module [default]...|
Updating module [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [13]
Build step 'Execute shell' marked build as failure
Finished: FAILURE
There is no specific pattern, and the error is not descriptive, but I noticed the following:
If I deploy to a new staging container and a new version it usually works the first time, but later on it doesn't
I suspect it has something to do with static resources, as if I add some more static resources files "The ones commented out in the app.yaml sample below" the deployment fails
I suspected it is related to the issue described here, but the set +e solution didn't work for me How/When does Execute Shell mark a build as failure in Jenkins?
This is the build command that I use
set +e
gcloud --project=projectid preview app deploy app.yaml --version=3 --promote --bucket gs://projectstagingbucket --force
And here is a sample of the app.yaml file:
handlers:
# Static pages
#- url: /(.*\.(htm|html|css|js))
# static_files: \1
# upload: .*\.(htm|html|css|js)
# application_readable: true
# Serve images as static resources.
#- url: /resources/(.*\.(ico|jpg|jpeg|png|xcf|gif|woff|woff2|cur|ttf|otf|eot|svg))
# static_files: resources/\1
# upload: /resources/.*\.(ico|jpg|jpeg|png|xcf|gif|woff|woff2|cur|ttf|otf|eot|svg)
# application_readable: true
# Serve images as static resources.
#- url: /vendor/(.*\.(ico|jpg|jpeg|png|xcf|gif|woff|woff2|cur|ttf|otf|eot|svg))
# static_files: vendor/\1
# upload: vendor/.*\.(ico|jpg|jpeg|png|xcf|gif|woff2|cur|woff|ttf|otf|eot|svg)
# application_readable: true
# Serve images as static resources.
#- url: /skins/(.*\.(ico|jpg|jpeg|png|xcf|woff2|gif|woff|cur|ttf|otf|eot|svg))
# static_files: skins/\1
# upload: skins/.*\.(ico|jpg|jpeg|png|xcf|gif|woff2|woff|cur|ttf|otf|eot|svg)
# application_readable: true
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
application_readable: true
#- url: /(.+\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))
# static_files: \1
# upload: .+\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)
# application_readable: true
- url: /robots.txt
static_files: robots.txt
upload: robots.txt
application_readable: true
# Misc files.
- url: /(.+\.(xsd|txt|sql|))
static_files: \1
upload: .+\.(xsd|txt|sql)
application_readable: true
# Serve MediaWiki installation scripts
# can be removed after installation
#- url: /mw-config/
# script: mw-config/index.php
# secure: always
# Serve mw-config images as static resources.
#- url: /mw-config/images/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))
# static_files: mw-config/images/\1
# upload: mw-config/images/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)
# application_readable: true
# Serve images from Google Cloud Storage
- url: /images/(.*\.(ico|jpg|jpeg|xcf|png|gif|woff|woff2|cur|ttf|otf|eot|svg))
script: extensions/CloudStorage/GoogleCloudStorageFileServe.php
secure: optional
# Serve php5 scripts.
- url: /(.+\.php5)
script: \1
# Serve php scripts.
- url: /(.+\.php)
script: \1
#
- url: (.*)/(.*)
script: index.php
secure: optional
# redirect root to wiki path
- url: /?
script: index.php
secure: optional
# 404
- url: /(.*)
# script: /wiki/Special:Error404
#
#- url: /wiki/Special:Error404
script: index.php
Thanks in advance.

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

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

GAE PHP - image (.jpg) file not found on the server

My image file is not found on the server. I declared it as static on my app.yaml:
- url: /sampleimage\.jpg
static_files: sampleimage.jpg
upload: sampleimage\.jpg
As you can see it's on the root directory, I tested it first on localhost and it is found:
localhost:8080/sampleimage.jpg
However when deployed on the web it's not there:
http://samplesite.appspot.com/sampleimage.jpg
I don't know what I'm doing wrong here because my favicon.ico which is also static file is working fine http://samplesite.appspot.com/favicon.ico.
complete app.yaml:
application: samplesite
version: 1
runtime: php
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /
script: index.html
- url: /sampleimage\.jpg
static_files: sampleimage.jpg
upload: sampleimage\.jpg

Categories