Skip to content

Commit 4a02416

Browse files
committed
Merge branch 'master' of https://github.com/code-runner-2017/php-lambda-layer into development
2 parents 41eb94b + 0644707 commit 4a02416

File tree

7 files changed

+99
-14
lines changed

7 files changed

+99
-14
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
php71.zip
2+
php72.zip
3+
php73.zip

Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
22

33
php71.zip:
4-
docker run --rm -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build.sh
4+
docker run --rm -e http_proxy=${http_proxy} -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build.sh
5+
6+
php72.zip:
7+
docker run --rm -e http_proxy=${http_proxy} -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build-php-remi.sh 2
8+
9+
php73.zip:
10+
docker run --rm -e http_proxy=${http_proxy} -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build-php-remi.sh 3
511

612
upload: php71.zip
713
./upload.sh
@@ -10,4 +16,5 @@ publish: php71.zip
1016
./publish.sh
1117

1218
clean:
13-
rm php71.zip
19+
rm -f php71.zip php72.zip php73.zip
20+

README.md

+36-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# PHP Layer For AWS Lambda
22

3-
Ever wanted to run PHP websites in AWS Lambda? It's your lucky day! This Lambda Runtime Layer runs the [PHP 7.1 webserver](http://php.net/manual/en/features.commandline.webserver.php) in response to [AWS API Gateway](https://aws.amazon.com/api-gateway/) or [AWS Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/features/#Details_for_Elastic_Load_Balancing_Products) requests.
3+
Ever wanted to run PHP websites in AWS Lambda? It's your lucky day! This Lambda Runtime Layer runs the [PHP 7.1/7.2/7.3 webserver](http://php.net/manual/en/features.commandline.webserver.php) in response to [AWS API Gateway](https://aws.amazon.com/api-gateway/) or [AWS Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/features/#Details_for_Elastic_Load_Balancing_Products) requests.
44

55
And, if you're looking for a great way to build serverless apps of all kinds, be sure to check out [Stackery](https://stackery.io)!
66

77
This is an early iteration of the PHP runtime Layer which is not yet ready for production. Please feel free to use this Layer to learn about the Lambda Layers feature and begin experimenting with PHP functions. We welcome feedback and stay tuned for the production-ready version coming soon.
88

99
## Current Layer Version ARN
10-
When creating/updating a Lambda function you must specify a specific version of the layer. This readme will be kept up to date with the latest version available. The latest available Lambda Layer Version ARN is:
10+
When creating/updating a Lambda function you must specify a specific version of the layer. This readme will be kept up to date with the latest version available. The latest available Lambda Layer Version ARN for PHP 7.1 is:
1111

1212
**arn:aws:lambda:\<region\>:887080169480:layer:php71:7**
1313

1414
See [Releases](https://github.com/stackery/php-lambda-layer/releases) for release notes.
1515

1616
### Usage
1717
#### General Usage
18-
The layer runs the PHP 7.1 [PHP webserver](http://php.net/manual/en/features.commandline.webserver.php) in /var/task, the root directory of function code packages:
18+
The layer runs the PHP 7.* [PHP webserver](http://php.net/manual/en/features.commandline.webserver.php) in /var/task, the root directory of function code packages:
1919

2020
```sh
2121
$ php -S localhost:8000 '<handler>'
@@ -26,12 +26,14 @@ The Lambda Function Handler property specifies the location of the the script ex
2626
#### Configuration Files
2727
There are three locations where PHP configuration may be located:
2828

29-
* Files in layer code packages located under /etc/php-7.1.d/
30-
* Files in function code package located under /php-7.1.d/
29+
* Files in layer code packages located under /etc/php-${PHP_VERSION}.d/
30+
* Files in function code package located under /php-${PHP_VERSION}.d/
3131
* php.ini located at the root of the function code package
3232

33+
Replace ${PHP_VERSION} with '7.1', '7.2', or '7.3' according to your preferred runtime.
34+
3335
##### Extensions
34-
The following extensions are built into the layer and available in /opt/lib/php/7.1/modules:
36+
The following extensions are built into the layer and available in /opt/lib/php/${PHP_VERSION}/modules:
3537

3638
```
3739
bz2.so
@@ -68,7 +70,7 @@ These extensions are not loaded by default. You must add the extension to a php.
6870
extension=json.so
6971
```
7072

71-
Extensions can be built using the lambci/lambda:build-nodejs8.10 Docker image. It is recommended that custom extensions be provided by a separate Lambda Layer with the extension .so files placed in /lib/php/7.1/modules/ so they can be loaded alongside the built-in extensions listed above.
73+
Extensions can be built using the lambci/lambda:build-nodejs8.10 Docker image. It is recommended that custom extensions be provided by a separate Lambda Layer with the extension .so files placed in /lib/php/${PHP_VERSION}/modules/ so they can be loaded alongside the built-in extensions listed above.
7274

7375
#### SAM Example
7476
Let's create an AWS SAM PHP application. We suggest using [Stackery](https://stackery.io) to make this super simple. It automates all the scaffolding shown below. But you may also choose to roll your own application from scratch.
@@ -149,6 +151,32 @@ Build the layer by:
149151

150152
This will launch a Docker container that will build php71.zip.
151153

154+
You can run `make php72.zip` and `make php73.zip` to create a layer that is based on PHP 7.2/7.3.
155+
156+
If you are behind a proxy server, just set the environment variable `http_proxy` before
157+
invoking `make`, eg.:
158+
159+
```sh
160+
$ export http_proyx=http://myproxy.acme.com:8080
161+
$ make php73.zip
162+
```
163+
164+
### Debugging
165+
166+
Run:
167+
168+
```sh
169+
$ docker run --rm -it -v `pwd`:/opt/layer lambci/lambda:build-nodejs8.10 /bin/bash
170+
```
171+
172+
If you are on Windows, run this instead:
173+
174+
```sh
175+
> docker run --rm -it -v %cd%:/opt/layer lambci/lambda:build-nodejs8.10 /bin/bash
176+
```
177+
178+
and execute manually the commands in the build.sh file.
179+
152180
### Disclaimer
153181

154182
> THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
@@ -162,4 +190,4 @@ This will launch a Docker container that will build php71.zip.
162190
> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
163191
> STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164192
> ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
165-
> OF THE POSSIBILITY OF SUCH DAMAGE.
193+
> OF THE POSSIBILITY OF SUCH DAMAGE.

bootstrap

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ function start_webserver() {
1717
case 0:
1818
// exec the command
1919
$HANDLER = getenv('_HANDLER');
20+
$phpMinorVersion = PHP_MINOR_VERSION;
2021
$handler_components = explode('/', $HANDLER);
2122
$handler_filename = array_pop($handler_components);
2223
$handler_path = implode('/', array_merge(['/var/task'], $handler_components));
2324
chdir($handler_path);
24-
exec("PHP_INI_SCAN_DIR=/opt/etc/php-7.1.d/:/var/task/php-7.1.d/ php -S localhost:8000 -c /var/task/php.ini -d extension_dir=/opt/lib/php/7.1/modules '$handler_filename'");
25+
exec("PHP_INI_SCAN_DIR=/opt/etc/php-7.${phpMinorVersion}.d/:/var/task/php-7.${phpMinorVersion}.d/ php -S localhost:8000 -c /var/task/php.ini -d extension_dir=/opt/lib/php/7.${phpMinorVersion}/modules '$handler_filename'");
2526
exit;
2627

2728
// return the child pid to parent

build-php-remi.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
PHP_MINOR_VERSION=$1
4+
5+
echo "Building layer for PHP 7.$PHP_MINOR_VERSION - using Remi repository"
6+
7+
yum install -y wget
8+
yum install -y yum-utils
9+
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
10+
wget https://rpms.remirepo.net/enterprise/remi-release-6.rpm
11+
rpm -Uvh remi-release-6.rpm
12+
rpm -Uvh epel-release-latest-6.noarch.rpm
13+
14+
15+
yum-config-manager --enable remi-php7${PHP_MINOR_VERSION}
16+
17+
yum install -y httpd
18+
yum install -y postgresql-devel
19+
yum install -y libargon2-devel
20+
21+
yum install -y --disablerepo="*" --enablerepo="remi,remi-php7${PHP_MINOR_VERSION}" php php-mbstring php-pdo php-mysql php-pgsql
22+
23+
24+
mkdir /tmp/layer
25+
cd /tmp/layer
26+
cp /opt/layer/bootstrap bootstrap
27+
sed "s/PHP_MINOR_VERSION/${PHP_MINOR_VERSION}/g" /opt/layer/php.ini >php.ini
28+
29+
mkdir bin
30+
cp /usr/bin/php bin/
31+
32+
mkdir lib
33+
for lib in libncurses.so.5 libtinfo.so.5 libpcre.so.0; do
34+
cp "/lib64/${lib}" lib/
35+
done
36+
37+
cp /usr/lib64/libedit.so.0 lib/
38+
cp /usr/lib64/libargon2.so.0 lib/
39+
cp /usr/lib64/libpq.so.5 lib/
40+
41+
mkdir -p lib/php/7.${PHP_MINOR_VERSION}
42+
cp -a /usr/lib64/php/modules lib/php/7.${PHP_MINOR_VERSION}/
43+
44+
zip -r /opt/layer/php7${PHP_MINOR_VERSION}.zip .
45+

build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
yum install -y php71-cli zip
3+
yum install -y php71-mbstring.x86_64 zip php71-pgsql php71-mysqli
44

55
mkdir /tmp/layer
66
cd /tmp/layer
@@ -16,6 +16,7 @@ for lib in libncurses.so.5 libtinfo.so.5 libpcre.so.0; do
1616
done
1717

1818
cp /usr/lib64/libedit.so.0 lib/
19+
cp /usr/lib64/libpq.so.5 lib/
1920

2021
cp -a /usr/lib64/php lib/
2122

php.ini

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
extension_dir=/opt/lib/php/7.1/modules
1+
extension_dir=/opt/lib/php/7.PHP_MINOR_VERSION/modules
2+
display_errors=On
3+
24
extension=curl.so
35
extension=json.so
4-
display_errors=On

0 commit comments

Comments
 (0)