Download a working version
Create Environment with PHP8.0 with Amazon Linux 2.
Setup Environment & Run application using Elastic Beanstalk.Download a working application version from Elastic beanstalk from the existing environment.
Use platform settings if needed and add +x permission to all the .platform files as follows:
chmod +x .platform/hooks/postdeploy/01_managePermissions.sh ... ...
Add hook file for folder permissions.
.platform/hooks/postdeploy/01_managePermissions.sh#!/bin/bash # Give permissions sudo chmod -Rf 777 /var/log/nginx sudo chmod -Rf 777 /var/log/php-fpm
Add hook file for starting the service on deployment.
.platform/hooks/postdeploy/02_environmentConfig.sh#!/bin/bash # chkconfig has been replaced by systemctl in Linux 2 instance. sudo systemctl enable nginx systemctl is-enabled nginx sudo service nginx start sudo service nginx status
Add above 2 files inside .platform/confighooks to execute it on every configuration change. To avoid duplicate code refer to the above file as the source.
.platform/confighooks/postdeploy/01_managePermissions.sh#!/bin/bash source "/var/app/current/.platform/hooks/postdeploy/01_managePermissions.sh"
.platform/confighooks/postdeploy/02_environmentConfig.sh#!/bin/bash source "/var/app/current/.platform/hooks/postdeploy/02_environmentConfig.sh"
Override the php.conf files as per the application requirement as follows :
.platform/nginx/conf.d/elasticbeanstalk/php.conf# Add root settings to the directory root /var/www/html/dist; index index.html index.htm index.php; # Comment this for local applications # Redirect to url with https if ($http_x_forwarded_proto != 'https') { return 301 https://$host$request_uri; } location / { try_files $uri $uri/ /index.html?$query_string; }
Create a new Environment.
Go to Elastic Beanstalk.
Create a new Environment. https://us-west-2.console.aws.amazon.com/elasticbeanstalk/home?region=us-west-2#/environments
Select environment tier → Web server environment.
Enter
Application Name,
Environment Name
Domain name [Optional]
Platform → Managed platform
Platform → PHP
Platform branch → PHP 8.0 running on 64bit Amazon Linux 2
Platform version → 3.3.7 (Recommended)
Application code → Upload your code
Source code origin → Local file → Choose file → Upload a working application version downloaded from Elastic beanstalk from the existing environment.
Click on → Configure more options
Set up Environment configuration page
Modify software :
Proxy server → Nginx
Document root →
Environment properties → [Provide the key-value pair for setting Environment variables.]
ENVIRONMENT: staging/production
Modify instances :
Root volume type → Container default
Size →
EC2 security groups → [select ssh security group if needed]
Modify capacity :
Auto scaling group → Environment type → Load Balancer
Scaling triggers →
Load Balancer : [Do later for HTTPS to avoid grey status]
Add this once the Environment is ready to avoid any failure.
Listeners → add 443 HTTPS
[Use Valide certificate from ACM
Check the HTTPS access using the test domains defined on Route53.]
Rolling updates and deployments :
Deployment policy → Rolling with additional batch
Rolling update type → Rolling based on Health. [If multiple instances available]
Security :
Virtual machine permissions → Choose EC2 key pair
Monitoring :
Health reporting → Enhanced
Click on → Create Environment
Use the Domain name to verify the functionality.
If needed restart/rebuild the EB environment.
Modify Application Load Balancer
Add Listener for Port - 443 - Https with valid Certificate details.
Modify Application Load Balancer → Processes → Edit “default” process
Update HTTP code → 301 [For web_client application)
To support the below redirection
# Redirect to url with https if ($http_x_forwarded_proto != 'https') { return 301 https://$host$request_uri; }
Update Route53 for the specific hosted zone
Deployment to the new Environment using Pipeline.
Update Pipeline with correct EB Environment name & EB Application name for deployment.
Run the pipeline to deploy updated code to the new environment.
If needed add ssh-keys for devs.
Setup Cloudwatch
Create AMI of the instance. Use the AMI ID on the EB configuration & update.
Note :
Restart apache after reboot instances with Amazon Linux 2 AMI
In Amazon Linux 2 AMI you need to follow these steps to restart apache after reboot:
In AMI2 they are using systemctl for managing services check if it is installed on your machine.
Use this command to check if nginx is listed
systemctl list-units --type=service
To enable nginx start on bootup
sudo systemctl enable nginx
To check if nginx enabled to start on bootup Linux system
systemctl is-enabled nginx
After this nginx will be started if we reboot the Linux system.