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.
Related
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.
I created a PHP web app which runs fine in localhost, but it is incorrectly formatted when I run it through GAE development server.
Do you have any idea why?
Correct format:
Incorrect format:
app.yaml:
runtime: php55
api_version: 1
handlers:
- url: /.*
script: index.php
You have to specify handlers for your static files so that they get uploaded with your deployed app:
runtime: php55
api_version: 1
handlers:
- url: /images
static_dir: images
- url: /css
static_dir: css
# Catch all handler for any other requests:
- url: /.*
script: index.php
Read more about using the static_dir or static_files options.
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!
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
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