I'm doing aa AWS EC2 tutorial (udemy course by Stephane Maarek) and he has us create an instance using the following script:
#!/bin/bash
# install httpd (Linux 2 version)
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable http
echo "<h1>Hello world from $(hostname -f)</h1>" > var/www/html/index.html
When I initially create the instance, I am able to navigate to the public IP of the instance. However, if I stop the instance and then restart it (as he does in the video lecture), when I go to the IP address, nothing happens.
I connect to the instance and enter the following: sudo systemctl status httpd
And, as expected, the httpd service is dead. I start it up by using: sudo system restart httpd.
Once I navigated again to the IP address of the instance, it worked, as expected.
I recall doing this tutorial over a year ago and did not experience this issue. I've created several instances over and over and each time I get the same issue.
The steps I followed to restart the httpd services are from: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-hosting-unresponsive-website/
Does anyone have any suggestions on what I should be looking at? I know I can move on as I'm only studying for the certified cloud practitioner exam....but not being able to figure this out for days is really bugging me. I refuse to keep going until I find out what's happening.
Thank you for your time.
CodePudding user response:
The issue would probably in this line:
systemctl enable http
This should be:
systemctl enable httpd
There is the "d" missing, so instead of "http" it must be "httpd". This will fix the not running httpd after restarting the EC2.
Another thing:
echo "<h1>Hello world from $(hostname -f)</h1>" > var/www/html/index.html
Should be not relative, it should be absolute, because based on your current directory, this won't place the content in the correct directory. So, change it to
echo "<h1>Hello world from $(hostname -f)</h1>" > /var/www/html/index.html
And if you get any issues with that command, try to check if that directory is available and you are able to write into it (using 'sudo').
CodePudding user response:
Not sure why my question was down voted. I spent over three days researching on my own, trying to figure out how web services worked, looked over httpd config file trying to learn (too afraid to make any changes because I had no idea what I was doing).
There were two other people that had similar issues and I was able to help them thanks to the answer I received here, so I'm grateful to user Daniel Seichter for his help.
Issue for me was a typo in the script that goes in the User Data for EC2 when creating an instance. Let this be a lesson to others, if possible cut and paste, don't copy code for scripts by hand. :-)