How do I redirect with dev_appserver? - php

I have a simple login script that checks mysql for authentication of the user and then redirects to the start page of the application using the php 'header' function.
if (mysqli_num_rows($dbq)==1) {
header("Location: header.html");
}
where header.html is in the same directory as index.php, but it seems to ignore this completely. The log simply says;
INFO 2016-03-22 13:36:48,421 module.py:787] default: "POST /index.php HTTP/1.1" 200 301
INFO 2016-03-22 13:36:48,517 module.py:787] default: "GET /favicon.ico HTTP/1.1" 200 301
Here is some more info - if I put
- url: /.*
script: index.php
I get the http status of 301, but if I remove this handler the redirection works.
Here is current app.yaml file;
application: crm
version: 1
runtime: php55
api_version: 1
threadsafe: yes
handlers:
# Serve php scripts.
#- url: /.*
# script: index.php
#- url: /.*
# script: header.html
- url: /(.+\.php)$
script: \1
- url: /(.+\.html)$
script: \1
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true

Related

App engine downloading PHP code instead of displaying

I'm using PHP55 to run a web-page on standard environment through Google App Engine. When I click the submit button on a form, it downloads the respective PHP code that should instead be executing. Here's my app.yaml:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /signUp.html
static_files: www/signUp.html
upload: www/signUp.html
- url: /submitEmail.php
static_files: www/submitEmail.php
upload: www/submitEmail.php
- url: /(.*)
static_files: www/\1
upload: www/(.*)
EDIT 1
So I initially tried the following for the handlers:
handlers:
-url: /(.+\.php)$
script: www/\1
-url: /
script: www/index.html
-url: /(.*)
script: www/\1
However this was in short - a disaster. Images and CSS didn't load after refreshing. All I want is for submitEmail.php to execute when the user clicks submit on the form in index.html.
To clarify this is my high-level structure:
www/
-index.html
-submitEmail.php
app.yaml
EDIT 2
Present state of app.yaml but when I submit the form I receive a 404 error.
handlers:
-url: /(.+\.php)$
script: www/\1
-url: /submitEmail.php
script: www/submitEmail.php
-url: /
script: www/index.html
-url: /(.*)
script: www/\1
Well the PHP code is delivered because you declared it as static_files. Static files are delivered as-is to the client when requested.
Change your handler like this:
- url: /submitEmail.php
script: www/submitEmail.php
upload: www/submitEmail.php
See also app.yaml reference.

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.

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

Joomla admin errors on google app engine php

Trying to get joomla working locally and ran into an issue with the Administror page. I have this error,
home page of site works - www.my-site.index.php
but with admin I find the following error - www.my-site/administrator.index.php
Warning: require(/Users/RichardClark/Sites/demo-test2/joomla/administrator): failed to open stream: No such file or directory in /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/php/setup.php on line 115
Fatal error: require(): Failed opening required '/Users/RichardClark/Sites/demo-test2/joomla/administrator' (include_path='/Users/RichardClark/Sites/demo-test2:/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/php/sdk') in /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/php/setup.php on line 115
I get the impressions joomla and google app engine aren't very compatible. I am really struggling to debug this. My app.yaml file is as follows;
application: fit-rig-517
version: 1
runtime: php
api_version: 1
handlers:
- url: /joomla/(.*\.(htm$|html$|css$|js$))
static_files: joomla/\1
upload: joomla/(.*\.(htm$|html$|css$|js$))
application_readable: true
## Admin
- url: /administrator(.+)
script: joomla/administrator\1
## Asset folders
- url: /media
static_dir: joomla/media
application_readable: true
mime_type: text/html
- url: /images
static_dir: joomla/images
application_readable: true
## Template folders
- url: /templates
static_dir: joomla/templates
application_readable: true
mime_type: application/(htm$|html$|css$|js$)
- url: /administrator/templates
static_dir: joomla/administrator/templates
application_readable: true
mime_type: text/html
## SEO robots
- url: /robots.txt
script: joomla/robots.txt
## Site access
- url: /(.+)?/?
script: joomla/index.php
thanks
App Engine does not have the concept of a default script (e.g. index.php) for directory access. Instead, it relies on the following rule in your app.yaml to locate the php script.
## Admin
- url: /administrator(.+)
script: joomla/administrator\1
Use /administrator/index.php to access your admin page instead.

Categories