Install Apache & PHP on EC2 Instance launch, or broadly run any shell script command while EC2 instance is initialising.
Put shell commands in userdata field of EC2 configuration, same way like you create .sh file and run it on any linux instance
Userdata in EC2 instance for Ubuntu 20.04