Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Commit

Permalink
Files for PHP 7.2 and 7.3 have been merged together
Browse files Browse the repository at this point in the history
  • Loading branch information
code-runner-2017 committed Feb 1, 2019
1 parent 7b6ea9a commit 557cbe4
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 655 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ php71.zip:
docker run --rm -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build.sh

php72.zip:
docker run --rm -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build-php72.sh
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

php73.zip:
docker run --rm -v $(ROOT_DIR):/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build-php73.sh
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

upload: php71.zip
./upload.sh
Expand Down
60 changes: 34 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# PHP Layer For AWS Lambda

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.
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.

This project is fork of the [Stackery](https://stackery.io) [php-lambda-layer](https://github.com/stackery/php-lambda-layer) that has been modified to:
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)!

- support PHP 7.1, 7.2, and 7.3 (the original supports 7.1 only) - using the [Remi RPM Repository](https://rpms.remirepo.net/)
- add support for mbstring, MySQL (pdo-mysql) and Postgres (pdo-pgsql)
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.

that are requirements for running frameworks such as [Lumen](https://lumen.laravel.com/) and [Laravel](https://laravel.com/) frameworks in serverless mode.
## Current Layer Version ARN
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:

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.
**arn:aws:lambda:\<region\>:887080169480:layer:php71:7**

If you need a layer for PHP 7.2 or 7.3, you can build your own.
You can find an example [here](http://tinyurl.com/ycsbfpbr).

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

### Usage
#### General Usage
Expand All @@ -24,14 +29,14 @@ The Lambda Function Handler property specifies the location of the the script ex
#### Configuration Files
There are three locations where PHP configuration may be located:

* Files in layer code packages located under /etc/php-<PHP_VERSION>.d/
* Files in function code package located under /php-<PHP_VERSION>.d/
* Files in layer code packages located under /etc/php-${PHP_VERSION}.d/
* Files in function code package located under /php-${PHP_VERSION}.d/
* php.ini located at the root of the function code package

Replace <PHP_VERSION> with 7.1, 7.2, or 7.3 according to your preferred runtime.
Replace ${PHP_VERSION} with '7.1', '7.2', or '7.3' according to your preferred runtime.

##### Extensions
The following extensions are built into the layer and available in /opt/lib/php/7.1/modules (PHP 7.1) or /opt/lib/php/modules (PHP 7.2/7.3):
The following extensions are built into the layer and available in /opt/lib/php/${PHP_VERSION}/modules:

```
bz2.so
Expand All @@ -45,20 +50,11 @@ ftp.so
gettext.so
iconv.so
json.so
mbstring.so
mysqli.so
mysqlnd.so
pdo.so
pdo_mysql.so
pdo_pgsql.so
pdo_sqlite.so
pgsql.so
phar.so
posix.so
shmop.so
simplexml.so
sockets.so
sqlite3.so
sysvmsg.so
sysvsem.so
sysvshm.so
Expand All @@ -77,7 +73,7 @@ These extensions are not loaded by default. You must add the extension to a php.
extension=json.so
```

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.
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.

#### SAM Example
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.
Expand Down Expand Up @@ -110,7 +106,7 @@ Resources:
Timeout: 30
Tracing: Active
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:887080169480:layer:php71:6
- !Sub arn:aws:lambda:${AWS::Region}:887080169480:layer:php71:7
Events:
api:
Type: Api
Expand Down Expand Up @@ -154,22 +150,34 @@ $ sam deploy \
Build the layer by:

1. Installing a Docker environment
2. Running `make`
1. Running `make`

This will launch a Docker container that will build php71.zip, based on PHP 7.1 (default).
This will launch a Docker container that will build php71.zip.

You can run `make php72.zip` and `make php73.zip` to create a layer that is based on PHP 7.2/7.3.

If you are behind a proxy server, just set the environment variable `http_proxy` before
invoking `make`, eg.:

```sh
$ export http_proyx=http://myproxy.acme.com:8080
$ make php73.zip
```

### Debugging

Run:

```sh
$ docker run --rm -it -v `pwd`:/opt/layer lambci/lambda:build-nodejs8.10 /bin/bash

```

If you are on Windows, run this instead:

```sh
> docker run --rm -it -v %cd%:/opt/layer lambci/lambda:build-nodejs8.10 /bin/bash

```

and execute manually the commands in the build.sh file.

### Disclaimer
Expand All @@ -185,4 +193,4 @@ and execute manually the commands in the build.sh file.
> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
> OF THE POSSIBILITY OF SUCH DAMAGE.
> OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 2 additions & 1 deletion bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function start_webserver() {
// exec the command
$HANDLER = getenv('_HANDLER');
chdir('/var/task');
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'");
$phpMinorVersion = PHP_MINOR_VERSION;
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'");
exit;

// return the child pid to parent
Expand Down
235 changes: 0 additions & 235 deletions bootstrap-php72

This file was deleted.

Loading

0 comments on commit 557cbe4

Please sign in to comment.