简体   繁体   中英

Can I run PHP files on Google App Engine for Python?

As a disclaimer, I'm new to app development.

So I've been working on this website using Google App Engine with the Python Runtime Environment. Problems arose when I was creating a simple form in HTML and decided to use PHP to store the data. Am I allowed to use PHP scripts when my application is being run in Python?

I also noticed that GAE now has a PHP runtime environment, so should I use that instead? I only used Python because it was easy to use at first and I didn't think I needed PHP.

This is what my main.py looks like, if it matters:

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

No, you will not be able to run PHP scripts in the Python runtime environment. If your application is more easily written in PHP, you can use the PHP runtime environment.

In app.yaml , set runtime: php , and create handlers: where the script: value is a PHP script:

applciation: helloworld
version: 1
runtime: php
api_version: 1

handlers:
- url: /.*
  script: helloworld.php

Then helloworld.php can be a PHP script, such as:

<?php
  echo 'Hello, world!';
?>

Note that you can use the same SDK for both Python and PHP.

You can't use PHP and Python on the same GAE environment. But you could translate your PHP code to Python, and use Python to store your data, or you could use PHP fully.

Take note that PHP is currently experimental:

The PHP runtime is available as an experimental Preview feature. Please be aware that the APIs and service may change before the service becomes Generally Available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM