2

Google official documentation is available here:
https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_PHP

But it doesn't provide sufficient information about the following step:
"4 - Build and install the PHP interpreter and App Engine PHP extension. Specify the path to php-cgi and gae_runtime_module.so when running the development server."

I'm using a new Virtualbox machine with Ubuntu 15.10 and PhpStorm to test GAE.

Could someone please provide clear instructions about step 4? What do I need to do to install the php interpreter and the App Engine php extension?

P.s. I've already searched with google but I only found old/confusing tutorials

Zeehad
  • 1,012
  • 1
  • 9
  • 11
Igor Carmagna
  • 957
  • 1
  • 10
  • 34

2 Answers2

4

That GAE PHP extension seems like a quite new thing. Don't remember using it on the SDK in Ubuntu 14.04.

You need to build PHP and that extension from source. You should grab the latest PHP5.5 branch from their source repo (http://php.net/git.php) and build it. That linked page contains instructions on building PHP but the procedure is similar to the following:

$ git clone <php-src> 
$ cd ./php-src/ 
$ git checkout PHP-5.5
$ ./buildconf
$ ./configure --prefix="/opt/php55"
$ sudo make && sudo make install

And remember to pick the modules and packages you want to compile with PHP5.5 to be used in the SDK. I think Google had an official list of modules and extensions they use inside GAE PHP and inside the SDK PHP. The prefix argument tells the compiler where to install the resulting application.

Then you need to get that source for the PHP extension and build it

$ git clone https://github.com/GoogleCloudPlatform/appengine-php-extension
$ cd appengine-php-extension
$ phpize # remember to use the phpize from the just built PHP5.5 binaries
$ ./configure
$ sudo make && sudo make install

(That Git repository contains detailed building instructions so you should probably refer to them when building.)

Enable the resulting .so for the PHP5.5 you just built using the PHP configuration files.

After that you need to install the PHP SDK and configure it to use the newly built PHP binary

$ dev_appserver.py <...> --php_executable_path=/opt/php55/bin/php-cgi

The SDK will let you know if the built PHP binaries are incompatible with the SDK version you use. I remember compiling the PHP from source around 5 times before it worked without any warnings.

But essentially they are telling you to compile PHP from source, then compile their extension from source and then use the built PHP+extension with the downloaded SDK. These instructions are from the top of my head so you may need to adjust the commands and procedures.

peak
  • 125
  • 5
ojrask
  • 2,799
  • 1
  • 23
  • 23
  • Thank you very much!! The process you described makes sense. I will try as soon as possible and accept the answer. I don't know how to enable .so for php in configuration files... hope to solve that with a google search – Igor Carmagna Feb 12 '16 at 10:03
  • 1
    As a side note, I think google should really simplify this process. I find other services (with hosting ad push to deploy) much easier to use/setup, since they only require you to have git and a Bitbucket/Github account. – Igor Carmagna Feb 12 '16 at 10:05
  • Yeah, GAE needs quite much upfront configuring to get it working properly on Linux (which is funny considering Google is known for requiring employees to use Linux from what I've heard). But once its done it should be fine until Google decides to introduce bigger changes. – ojrask Feb 12 '16 at 10:59
  • I'm having troubles with the first part: building and installing the PHP interpreter (https://github.com/GoogleCloudPlatform/appengine-php). When I execute the "make" command I always get the following error: /home/mark/Experiments/appengine-php/php-src/ext/libxml/libxml.c:39:27: fatal error: libxml/parser.h: No such file or directory compilation terminated. Makefile:500: recipe for target 'ext/libxml/libxml.lo' failed make: *** [ext/libxml/libxml.lo] Error 1 – Igor Carmagna Feb 13 '16 at 14:57
  • P.s. I already executed sudo apt-get install libxml2-dev BUT did not work – Igor Carmagna Feb 13 '16 at 14:58
  • Did you get it working? Found something related: http://stackoverflow.com/questions/29847814/compiler-cant-find-libxml-parser-h I'm not sure whether makefiles have some "checker" available to list dependencies as is. – ojrask Feb 15 '16 at 07:45
  • I couldn't solve that problem and I used your advice (I git cloned php official repo instead) but I don't know if that will cause problems because of a different configuration. Now I'm stuck with a different problem: see this question http://stackoverflow.com/questions/35390935/ubuntu-right-protobuf-paths-for-configure-command Could you please give it a glance? As a side note, could you please clarify how to actually use the infos that you linked? (should I run the g++ command as a parameter after make or else ... sorry I'm a bit lost... I already tried various combinations but no luck) – Igor Carmagna Feb 15 '16 at 08:14
  • I had to clone the official PHP repo too, forgot to mention that, apologies! I have not compiled the GAE extension myself but I'll check it out and see whether I find anything which could help. :) – ojrask Feb 15 '16 at 08:22
  • It should be noted that you should do all of this in a VM, Chroot or container. The PHP Runtinme Extension has build paths that are hard to wrap without a chroot. – Ray Foss Sep 06 '16 at 14:46
1

The process can be simplified by using Docker, here is an image you can use: https://hub.docker.com/r/mhariri/docker-google-appengine-php/

To run your app, you just need docker installed, and then run the following command in your app directory:

docker run -it -v $(pwd):/app --rm --net=host mhariri/docker-google-appengine-php
peak
  • 125
  • 5
  • Did your pull request fix this issue? – peak Sep 07 '16 at 19:43
  • It did! While php.ini was being read, and it was properly configured to take libxml calls in App Engine, the module wasn't installed on the docker container. There is a long list of modules App Engine supports that aren't installed. Would be nice to build a small test to check if every module is installed and working... such as MongoDB which I'll need soon. – Ray Foss Sep 08 '16 at 02:33