GithubHelp home page GithubHelp logo

lysomuch / serverless-php-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from canopas/serverless-php-example

0.0 1.0 0.0 9.37 MB

Example of serverless PHP which supporting to deploy AWS lambda function with Laravel and Codeigniter

Dockerfile 39.47% Shell 19.70% PHP 40.83%

serverless-php-example's Introduction

Serverless Todo in PHP

This repository is an example of deploying PHP web applications on AWS Lambda. This example uses Custom PHP runtime for deploying lambda function. We can deploy Laravel or Codeigniter applications by simply putting their source code to php/src directory. By Creating API-Gateway in AWS, We can check our running web applications.

Prerequisites

Quick Start

  1. Clone the repo
git clone https://github.com/canopas/serverless-php.git
cd serverless-php
  1. Configure your AWS credentials, region and IAM role in php/deploy.sh

  2. Run DockerFile To deploy Lambda function.

docker build .

Platforms Supports

As this repo support integration for both Laravel and CodeIgniter, There are some prerequisites before deploying lambda functions for each type of application.

  • Set platforms in php/runtime.php according your need.

  • Put source code in php/src directory.

  • If you are using codeigniter, Update $app->run() in public/index.php to

    $response = $app->run();
    

Storage

  • AWS cannot write logs or cache in Lambda function's directory, we have to change configuration of those in their config files.

  • You can configure database or redis for sessions and cache and stdout for logs in Laravel And Codeigniter.

Explanation

  • DockerFile

    • Used two docker image,
      • First for compile php binary, that binary will used by further docker image.
      • Second for generating zip files for runtime and functions and deploying Lambda function.
    • runtime.zip contains bootstarp, runtime.php, php-cgi, vendor and extra-libraries. It will deploy in Lamda's opt directory.
    • src.zip contains src.
  • bootstarp & runtime.php

    • Bootstrap is entrypoint for custom PHP runtime. It executes runtime.php.

    • runtime.php contains code to handle php on AWS Lambda with the reference of this example.

    • It every time calls index.php to serve incoming requests.

  • php-cgi

    • It is the binary file for executing lambda function.We are using php-cgi because our goal is to deploy serverless php web applications.
  • vendor

    • It contains guzzlehttp/guzzle package dependency for serving http requests.
  • extra-Libraries

    • AmazonLinux2 does not provide all shared libraries, those are required by php execution. We can encounter error when running Lambda function.

      error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory.
      
    • We have to add those libraries manually.

    • I have added some of those here, and you can add others too by following instructions.

      • Make a directory name extra-libraries
      • Copy all required libraries from Amazon Linux to extra-libraries by using following steps :
        • Run amazon Linux docker instance using docker run --rm -it -v :/opt:rw,delegated amazonlinux:latest
        • Then in docker instance make directory using mkdir deps
        • Copy all required libraries from lib64 to deps directory using cp -f lib64/libcrypt.so.1 deps (Taken libcrypt.so.1 for reference)
        • Then open another terminal window and move all library files to local extra-libs using docker cp <DOCKER_CONTAINER_ID>:/deps/ . && mv deps/* ./extra-libraries
    • Updated LD_LIBRARY_PATH in bootstrap, to point this extra-libraries in AWS lambda runtime.

  • src

    • It contains index.php file for serving our php web applications.

serverless-php-example's People

Contributors

cp-sumi-k avatar

Watchers

James Cloos avatar

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.