serverless-php icon indicating copy to clipboard operation
serverless-php copied to clipboard

How to build with redis?

Open niron1 opened this issue 7 years ago • 3 comments

Hi, it seems like building with redis is not part of the default php build options. how can this be done? and is there a general way to add .so extensions to the php on lambda?

niron1 avatar Apr 23 '18 06:04 niron1

Hi You can rebuild the PHP binary with any flags you desire as per the readme: https://github.com/araines/serverless-php#rebuilding-php-binary

If you have a look in the dockerfile in particular: https://github.com/araines/serverless-php/blob/master/dockerfile.buildphp

You can see where all the flags are being added. Hopefully that resolves your issue :)

araines avatar Apr 23 '18 07:04 araines

Hi Both links you provided do not even reveal the ability to build with mysql / pdo. In this link, it does show that mysql / pdo could be indeed included: https://apple.stackexchange.com/questions/10400/how-can-i-determine-the-compile-time-options-of-php

However, what about other libraries that are not mentioned? redis is just one important example.

niron1 avatar Apr 23 '18 07:04 niron1

Apologies, I didn't realise Redis wasn't coming in via a build flag on PHP. The dockerfile gives you the ability to run anything you want within the Amazon Linux environment (as required by Lambda). This means that in principle you can run all the wget and make commands you need, and produce the appropriate output files from there.

All we are doing here is running an Amazon Linux environment in the docker container and then building PHP in there and extracting the resultant binary back out so it can be run on Lambda. So feel free to extend this to whatever needs you have, including any external libs etc that you require. Libraries which come "built in" with PHP are obviously a more simple task, as you just need to add more arguments in the dockerfile, but there is nothing to stop you from doing more.

After building your libs, I'd say you'd want to extract the binary lib files (.so etc) in a similar way to how the PHP binary itself is pulled out and put them somewhere sensible within your project.

You'll then need to use a non-standard php.ini -- you'll want to create one of these yourself in your project directory somewhere, then probably alter this file where it starts PHP to include additional arguments (e.g. php -c php.ini) to load your ini file(s). You can then add your extensions in there.

Ultimately you are building and configuring PHP here, so whilst I've not explicitly described exactly how to do it for your use case, its pretty well documented on the PHP site and in various other places around the net. Unfortunately the current state of play is that you need to be fairly comfortable with doing that in order to get things working with PHP on Lambda.

I hope that clarifies things

araines avatar Apr 23 '18 08:04 araines