{"id":21898504,"url":"https://github.com/canopas/serverless-php-example","last_synced_at":"2025-04-15T18:43:29.603Z","repository":{"id":86025873,"uuid":"310216922","full_name":"canopas/serverless-php-example","owner":"canopas","description":"AWS lambda function with Laravel and Codeigniter -- serverless example","archived":false,"fork":false,"pushed_at":"2022-03-30T04:25:18.000Z","size":9598,"stargazers_count":7,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T23:51:09.442Z","etag":null,"topics":["aws","aws-lambda","codeigniter","dockerfile","lambda","laravel","php","serverless"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/canopas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-05T07:07:03.000Z","updated_at":"2024-11-19T00:07:03.000Z","dependencies_parsed_at":"2023-04-17T22:53:32.121Z","dependency_job_id":null,"html_url":"https://github.com/canopas/serverless-php-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canopas%2Fserverless-php-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canopas%2Fserverless-php-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canopas%2Fserverless-php-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/canopas%2Fserverless-php-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/canopas","download_url":"https://codeload.github.com/canopas/serverless-php-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249131545,"owners_count":21217767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda","codeigniter","dockerfile","lambda","laravel","php","serverless"],"created_at":"2024-11-28T14:32:55.488Z","updated_at":"2025-04-15T18:43:29.598Z","avatar_url":"https://github.com/canopas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverless Todo in PHP\n\nThis repository is an example of deploying PHP web applications on AWS Lambda. \nThis example uses Custom PHP runtime for deploying lambda function.\nWe can deploy __Laravel__ or __Codeigniter__ applications by simply putting their source code to `php/src` directory.\nBy Creating API-Gateway in AWS, We can check our running web applications.\n\n## Prerequisites\n\n- [Docker](https://docs.docker.com/get-docker/)\n\n## Quick Start\n\n1) Clone the repo\n\n```\ngit clone https://github.com/canopas/serverless-php.git\ncd serverless-php\n```\n\n2) Configure your AWS credentials, region and IAM role in `php/deploy.sh`\n\n3) Run DockerFile To deploy Lambda function.\n\n```\ndocker build .\n```\n\n## Platforms Supports\n\nAs this repo support integration for both Laravel and CodeIgniter, There are some prerequisites before deploying lambda functions for each type of application.\n\n- Set platforms in `php/runtime.php` according your need.\n\n- Put source code in `php/src` directory.\n\n- If you are using codeigniter, Update `$app-\u003erun()` in `public/index.php` to\n    ````\n    $response = $app-\u003erun();\n    ````\n\n#### Storage\n\n- AWS cannot write logs or cache in Lambda function's directory, we have to change configuration of those in their config files.\n\n- You can configure `database` or `redis` for sessions and cache and `stdout` for logs in Laravel And Codeigniter.\n\n## Explanation\n\n- #### DockerFile\n     - Used two docker image, \n          - First for compile php binary, that binary will used by further docker image.\n          - Second for generating zip files for runtime and functions and deploying Lambda function.\n     - `runtime.zip` contains bootstarp, runtime.php, php-cgi, vendor and extra-libraries. It will deploy in Lamda's `opt` directory.\n     - `src.zip` contains src.\n      \n- #### bootstarp \u0026 runtime.php\n     - Bootstrap is entrypoint for custom PHP runtime. It executes `runtime.php`.\n    \n     - `runtime.php` contains code to handle php on AWS Lambda with the reference of [this example](https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/).\n     \n     - It every time calls index.php to serve incoming requests.\n       \n- #### php-cgi\n     - It is the binary file for executing lambda function.We are using php-cgi because our goal is to deploy serverless php web applications.\n    \n- #### vendor\n     - It contains `guzzlehttp/guzzle` package dependency for serving http requests.\n     \n- #### extra-Libraries\n     - AmazonLinux2 does not provide all shared libraries, those are required by php execution. We can encounter error when running Lambda function.\n        ````\n        error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory.\n        ````\n        \n     - We have to add those libraries manually.\n     \n     - I have added some of those here, and you can add others too by following instructions.\n    \n         - Make a directory name `extra-libraries`\n         - Copy all required libraries from Amazon Linux to `extra-libraries` by using following steps :\n              - Run amazon Linux docker instance using `docker run --rm -it -v :/opt:rw,delegated amazonlinux:latest`\n              - Then in docker instance make directory using `mkdir deps`\n              - Copy all required libraries from lib64 to deps directory using `cp -f lib64/libcrypt.so.1 deps` (Taken libcrypt.so.1 for reference)\n              - Then open another terminal window and move all library files to local extra-libs using \n                `docker cp \u003cDOCKER_CONTAINER_ID\u003e:/deps/ . \u0026\u0026 mv deps/* ./extra-libraries`\n                \n     - Updated `LD_LIBRARY_PATH` in bootstrap, to point this extra-libraries in AWS lambda runtime.\n\n- #### src\n     - It contains `index.php` file for serving our php web applications. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanopas%2Fserverless-php-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanopas%2Fserverless-php-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanopas%2Fserverless-php-example/lists"}