├── README.md ├── compile.sh ├── index.js ├── index.php └── php /README.md: -------------------------------------------------------------------------------- 1 | # aws-lambda-php-template 2 | Precompiled PHP 5.6 for AWS Lambda 3 | 4 | This repository contains the binary version of PHP 5.6 5 | and the necesary NodeJS code to run it on AWS Lambda 6 | 7 | It is statically linked to avoid missing libraries 8 | 9 | It's compiled with GD and phar support 10 | 11 | Less extensions included to stay within the Lambda zip file limit 12 | 13 | 14 | 15 | START RequestId: d176c2f7-2fdc-11e5-8fea-515246752d7d 16 | 2015-07-21T19:15:16.764Z d176c2f7-2fdc-11e5-8fea-515246752d7d array(3) { 17 | ["key3"]=> 18 | string(6) "value3" 19 | ["key2"]=> 20 | string(6) "value2" 21 | ["key1"]=> 22 | string(6) "value1" 23 | } 24 | Array 25 | ( 26 | [ 27 | 2015-07-21T19:15:16.765Z d176c2f7-2fdc-11e5-8fea-515246752d7d 0] => Core 28 | [1] => date 29 | [2] => ereg 30 | [3] => libxml 31 | [4] => openssl 32 | [5] => pcre 33 | [6] => curl 34 | [7] => standard 35 | [8] => gd 36 | [9] => hash 37 | [10] => json 38 | [11] => mbstring 39 | [12] => SPL 40 | [13] => Phar 41 | [14] => Reflection 42 | [15] => SimpleXML 43 | [16] => sockets 44 | [17] => exif 45 | [18] => xml 46 | [19] => mhash 47 | ) 48 | 49 | 2015-07-21T19:15:16.766Z d176c2f7-2fdc-11e5-8fea-515246752d7d child process exited with code 0 50 | END RequestId: d176c2f7-2fdc-11e5-8fea-515246752d7d 51 | REPORT RequestId: d176c2f7-2fdc-11e5-8fea-515246752d7d Duration: 55.91 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 12 MB 52 | 53 | 54 | 55 | 56 | # Next: 57 | 58 | *php.ini 59 | 60 | *ext/ folder to load needed extensions 61 | 62 | *PhantomJS 63 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PWD=pwd 4 | 5 | yum install -y libexif-devel libjpeg-devel gd-devel curl-devel openssl-devel libxml2-devel 6 | 7 | cd /tmp 8 | wget http://ro1.php.net/get/php-5.6.5.tar.gz/from/this/mirror -O php-5.6.5.tar.gz 9 | rm -rf php-5.6.5/ 10 | tar zxvf php-5.6.5.tar.gz 11 | 12 | cd php-5.6.5/ 13 | 14 | ./configure --prefix=/tmp/php-5.6.5/compiled/ \ 15 | --without-pear \ 16 | --enable-shared=no \ 17 | --enable-static=yes \ 18 | --enable-phar \ 19 | --enable-json \ 20 | \ 21 | --disable-all \ 22 | --with-openssl \ 23 | --with-curl \ 24 | \ 25 | --enable-libxml \ 26 | --enable-simplexml \ 27 | --enable-xml \ 28 | \ 29 | --with-mhash \ 30 | \ 31 | --with-gd \ 32 | --enable-exif \ 33 | --with-freetype-dir \ 34 | \ 35 | --enable-mbstring \ 36 | \ 37 | --enable-sockets 38 | 39 | make 40 | make install 41 | 42 | cd $PWD 43 | 44 | 45 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // For development/testing purposes 2 | 3 | var spawn = require('child_process').spawn 4 | var stream = require('stream') 5 | 6 | exports.handler = function( event, context ) { 7 | 8 | var php =spawn('./php', ['index.php']) 9 | php.stdin.setEncoding = 'utf-8'; 10 | php.stdin.write(JSON.stringify(event) + "\n") 11 | php.stdin.end() 12 | 13 | //php.stdout.pipe(process.stdout); 14 | 15 | 16 | 17 | php.stdout.on('data', function (data) { 18 | console.log( data.toString() ); 19 | }); 20 | 21 | php.stderr.on('data', function (data) { 22 | console.log( data.toString() ); 23 | }); 24 | 25 | //var readable = new stream.Readable(); 26 | //readable._read = function noop() {}; // See note below 27 | //readable.push('test me!'); 28 | //readable.push(null); 29 | //readable.pipe(php.stdin) 30 | 31 | php.on('exit', function (code) { 32 | console.log('child process exited with code ' + code); 33 | context.done() 34 | }); 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awspilot/aws-lambda-php-template/547385e1a490cd2e721f413e5f850959ce9ac9bc/php --------------------------------------------------------------------------------