GithubHelp home page GithubHelp logo

araines / serverless-php Goto Github PK

View Code? Open in Web Editor NEW
150.0 10.0 22.0 8.22 MB

PHP for AWS Lambda via Serverless Framework

License: MIT License

Shell 10.52% JavaScript 21.19% PHP 68.29%
serverless serverless-framework php

serverless-php's Introduction

serverless-php

serverless language license

PHP for AWS Lambda via Serverless Framework using Symfony components for dependency injection.

Latest version is on master.

AWS Lambda lets you run code without thinking about servers. Right now you can author your AWS Lambda functions in several langauges natively, but not PHP. This project aims to provide a fully featured shim for authoring your AWS Lambda functions in PHP.

More information about how this works and its performance characteristics can be found on my blog post.

Preview

<?php

use Raines\Serverless\Context;
use Raines\Serverless\Handler;

class HelloHandler implements Handler
{
    public function handle(array $event, Context $context)
    {
        return [
            'statusCode' => 200,
            'body' => 'Hello World!',
        ];
    }
}

Features

Event Data Context Logging Exceptions Environment API Gateway
full full part none full full

Usage

Prerequisites

Install this project:

serverless install --url https://github.com/araines/serverless-php

Currently serverless install does not work with Git LFS. Hopefully this will be supported in the future, but for the moment here are your options:

  1. Rebuild the PHP binary (described later in this document)
  2. Download the PHP binary directly from GitHub
  3. Instead of using serverless install, ensure you have Git LFS installed on your system and clone the repository.

Deploying to AWS

composer install -o --no-dev
serverless deploy

Running locally

serverless invoke local -f hello

Running on AWS

serverless invoke -f hello

Rebuilding PHP Binary

The PHP binary can be built with any flags you require and at any version.

Prerequisites

Compiling

sh buildphp.sh

Altering compile flags etc

Edit buildphp.sh and dockerfile.buildphp to alter it.

Thanks

serverless-php's People

Contributors

amitmerchant1990 avatar bmoffatt avatar jakzal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serverless-php's Issues

Works locally, but fails on AWS Lambda :(

Dear Author,

Please help.

I have successfully installed and configured serverless-php on both local and AWS Lambda. The function works as expected locally but does not work when it is invoked over AWS Lambda.

When invoked locally, the execution is SUCCESSFUL. https://www.screencast.com/t/KfIVnmRdVOF

When invoked online, the execution FAILS. https://www.screencast.com/t/ptootyYsFATF

When executed from AWS Lambda, it FAILS. https://www.screencast.com/t/qxFTk77X2

Looks like the child process call from the handler.js file is not getting executed for some reason.
var proc = child_process.spawn(php, args, options);

My local system is a Windows 10 x64 machine. Not sure if it has anything to do with Windows.

I tried to find a solution for this but a lot of other people are also struggling in getting it to work properly. Please help me fix this issue.

Suggestion: If possible please do a video tutorial of getting serverless-php up and running for Windows 10.

Looking forward to an early response.

Thanks & regards,
Mohit

README does not mention need for GIT-LFS

Seems I made quite a big oversight when I put the readme together and forgot to mention that git-lfs is required to pull the php executable bundled here, leading to some confusion for users not used to using lfs.

Additionally, Serverless framework does not appear to support Git LFS when doing the install command, so will have to provide some workarounds in the README

OPENSSL_1.0.2 not found

Getting an error when running the compiled executable for php:

2017-10-30T21:58:44.187Z 0a6e712e-c0a9-1b29-37a5-02f7da74f5fb stderr: ./php: /lib64/libcrypto.so.10: version `OPENSSL_1.0.2' not found (required by ./php)

Have you encountered this before? We are pretty confident this was working a few weeks ago and now all the sudden hitting this wall.

header('Location: redirect_url') unsupported

Hey there - I'm using serverless-php to serve PHP webpages. It looks like PHP's header() function isn't supported when I try to redirect to another URL since it breaks the handle.js shim when it runs the 'PHP execution end' JS. There is an attempt to JSON.parse() on an empty string which produces a fatal error.
2017-11-09T12:06:05.717Z 5c7d2f8c-c546-11e7-a243-51e367c4e01a SyntaxError: Unexpected end of JSON input at Object.parse (native)

I've attempted to put a conditional on this to check whether 'response' is an empty string or not but then I simply get a {"message": "Internal server error"} message from Lambda.

My workaround is to send an XHTML redirect back to the shim:
<meta http-equiv="refresh" content="0; url={{ redirect_url }}" />

This works - but I was wondering whether there is a better method to handle redirects?

Cheers!

compiling php with pdo ?

it seems like the compilation script provided is not buildling php with pdo.
when executing on Lambda, I get: Uncaught Error: Class 'PDO' not found in .....
anyone knows how to build the amazon linux php with pdo and mysql (and redis...) ?

How to build with redis?

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?

Please add lambda layer support

Hello,
Please add the lambda layer support for this project.

Requirements:

  • php (Php executable binary)
  • bootstrap (The file that initialize the layer)
  • php.ini (configuration for extensions)
  • hello.handler.php (The file that shows how it it works suc as "Hello world")

Best regards.
Thanks...

Is the new PHP file working?

I'm trying to deploy with the latest version and I'm getting this error

Serverless: Invoke invoke
{
    "errorMessage": "Process error code 1: ",
    "errorType": "Error",
    "stackTrace": [
        "ChildProcess.<anonymous> (/var/task/handler.js:47:23)",
        "emitTwo (events.js:106:13)",
        "ChildProcess.emit (events.js:191:7)",
        "maybeClose (internal/child_process.js:886:16)",
        "Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)"
    ]
}

  Error --------------------------------------------------

  Invoked function failed

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

This is a fresh install (no modifications).

Anybody else facing this problem with the latest version? Is this because of the new PHP file (earlier it was working fine).

Symfony 3.4 Requires hash()

Out of the box this no longer works with Symfony 3.4 due to the requirement on the hash() function.

It needs to be added as a compiler flag on the PHP build.

SLS deploy not working anymore after nodjes6 deprecation

After the NodeJS 6 deprecation by AWS the serverless deploy no longer works.

The runtime configured to NodeJS 6.10 in serverless.yml:

...
provider:
  name: aws
  runtime: nodejs6.10
...

Causes the following error on Serverless deploy

$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service xxx-serverless-php.zip file to S3 (3.92 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
................
Serverless: Operation failed!
Serverless: View the full error output: https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stack/detail?stackId=xxxxxxxxxxxxx

  Serverless Error ---------------------------------------

  An error occurred: HelloLambdaFunction - The runtime parameter of nodejs6.10 is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs12.x) while creating or updating functions. (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx).

Rebuilding with --enable-dom causes libssl error

I tried to use the build script after adding --enable-dom to the compile flags and once completed doing a ./php -v on the compiled binary causes the following error:

./php: /usr/lib/libssl.so.10: version `libssl.so.10' not found (required by ./php)
./php: /usr/lib/libcrypto.so.10: version `OPENSSL_1.0.1' not found (required by ./php)
./php: /usr/lib/libcrypto.so.10: version `OPENSSL_1.0.1_EC' not found (required by ./php)
./php: /usr/lib/libcrypto.so.10: version `libcrypto.so.10' not found (required by ./php)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.