3

I am trying to deploy a PHP through AWS CodeDeploy and am currently stuck on the AllowTraffic step in CodeDeploy. The application is on an EC2 instance behind an ALB. In the ALB, I am getting failing health checks. I have the PHP application code sitting in the following directory on the EC2 instance: /var/www/html/src. If I were to curl the private IP of the EC2 following by the directory where the code sits, I am getting an error 404 Not Found. Even though the index.php file is in that directory, I am unable to curl it. Currently I have security groups setup where the ALB security group allows any traffic from only HTTP, and all traffic from the ALB security group is allowed to reach the EC2 instance. I am able to curl the root of the instance and see Apache's default page.

If I were to adjust the health check settings on the ALB Target group, I get a 403 error when setting the health check to /. I get a 404 error when specifying the path to the directory that has the PHP application code.

Any advice on how I can get the instance to a healthy state for the ALB would be appreciated.

TG Health Check enter image description here

Application Load balancer security group allows traffic on port 80 EC2 instance security group allows traffic from Application Load Balancer security group.

The PHP application should be accessible on port 80, where Apache is running. The Application Load Balancer has only 1 listener that is set up for port 80, that forwards traffic to the target group.

asked Feb 16, 2022 at 3:15
4
  • can you shift your code to /var/www/html/index.php, also why are you checking with private IP, try with the public IP of ec2 instance Commented Feb 16, 2022 at 3:18
  • I will try moving up one directory. I have the instance in a private subnet with no public IP address. Commented Feb 16, 2022 at 3:20
  • 1
    You have to provide the exact settings of your TG's heath checks, security groups, application details (which ports it uses), listeners, etc... Commented Feb 16, 2022 at 3:22
  • I made edits to the OP. Commented Feb 16, 2022 at 3:32

2 Answers 2

2

The heath check path in your TG should be URL path, not the actual location on the EB instance. You can try with just /index.php:

/index.php

This assumes that your application is actually working and the only issue are health checks.

answered Feb 16, 2022 at 3:33
Sign up to request clarification or add additional context in comments.

3 Comments

The application is working. If I navigate to the load balancer DNS address and on /index.php, I get a working result. But the health checks are still failing.
@DaveMichaels The HC specifies 200 response code. Maybe your app returns different code. You have to verify that as well.
Actually, the instance did come back as healthy. I guess it just took some time.
0

In case you are using Laravel 11+.

Laravel 11 includes a health /up endpoint for new applications. Laravel introduced major changes to bootstrap/app.php. From this file, you can customize your application's routing, middleware, service providers, exception handling, and more.

You now have a new health parameter defined in the withRouting method, which is defined by default in the Laravel 11 skeleton. By default, the health route will forward the traffic to '/up' path, which you can use later for health checking processes in platforms like AWS.

Application::configure(basePath: dirname(__DIR__))
->withProviders()
->withRouting(
 web: __DIR__.'/../routes/web.php',
 api: __DIR__.'/../routes/api.php',
 commands: __DIR__.'/../routes/console.php',
 channels: __DIR__.'/../routes/channels.php',
 health: '/up', 
)
->withMiddleware()
->withExceptions()

You can change the route to suit your needs.

answered May 4, 2024 at 6:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.