If you find yourself wanting to use Nginx and PHP-FPM instead of apache for your AWS Beanstalk PHP App, well good for you!
This is a sample deployment with all of the .ebextensions to do so without having to make a custom AMI
You can pull down this repo, zip up the contents, making sure you include the .ebextensions directory and deploy to your beanlstalk application. Once the deployment has finished you should be able to hit your beanstalk ip and get the hello world response.
Environment variables are set in the /etc/nginx/fastcgi_params_env file and you can include them in your server block. You'll see an example of this in the default. This file will get updated with any environment variable changes on both application and config deployments.
You can get environment variables in your php script with:
getenv('ENV_VARIABLE_NAME)
You'll find the base config files within the .ebextensions directory. You can modify as needed and they will take effect when you deploy.
You can go this route, but then in a few months when you want to use the latest version of amazon linux you'll need to completely recreate your custom AMI all over again. That gets to be a pain over the course of time. So, why not just stick with the default AMI and handle all of your setup via .ebextensions?
Take a look at the .ebextensions/01_setup.config file. I've commented each step. Things in the "commands" section happen early in the deployment process before your actual code is setup.
This ends up being a complete pain. Beanstalk has many commands baked in with apache, so it just gets troublesome to get them all. So instead we keep apache in place but just tell Elasticbeanstalk to disable it.