digitalspeed logo

How to Restart Apache2 Web Server to Restore your EC2 Website 

troubleshoot web server issues

Have you been in a situation where you installed or made some update to your EC2 instance and quickly noticed that it is no longer responding to page requests, which requires you to try and configure, update, and reboot the server.

Handling server issues, and configurations like this is one of the main reasons why people choose serverless or fully managed cloud technologies. 

This could be due to many reasons like blocking firewall (security group rule), ACL rule for subnet, internal firewall rule on the server, etc. In this case you can simply reconfigure your VPC to allow access from the internet (0.0.0.0/0) through the specific ports like 8o, 8080 for HTTP, 24 for SSH, and 443 for HTTPS. Check out this post to learn how to configure the VPC or SG to be publicly accessible. 

In other cases, your website not being accessible due to the modifications you made to the instance simply means that the web server (Apache or Nginx) is not running (as shutdown). I explained how to troubleshoot and fix this issue below.

Prerequisite

  • You should have an EC2 or any other virtual server instance setup and running a web server. 
  • You can access servers remotely through SSH, therefore you should have SSH on their command line. 
  • Most have made the EC2 instance accessible through SSH, this simply means you have allowed SSH connection to the instance from the instance security group.

Troubleshooting

How can you know that your instance is not responding due to internal server software issues rather than a very strict or improperly configured VPC / SG (Security Group). 

You can use a Ping command to check the connectivity between your local computer and your remote EC2 instance. See the code below. 

ping –c 3 <public IP address of instance> 

You can also try a curl command to it to see if you get a response from the instance. Here’s the code below. 

Curl http://<Ip address> 

What I would recommend is that you SSH to the instance from your remote computer, with SSH you don’t only request data from the instance, you can also run administrative tasks, installations, update, commands on your instance remotely. 

Suppose you can connect to your instance through SSH and you confirm that you have made configuration for your instance SG (Security Group) to receive both SSH and HTTP connection. In that case, it clearly shows that your website is not responding because of an internal server issue, here’s how you can fix it. 

Before you get your hands busy, I would advise you make a snapshot or image (AMI) of your EC2 instance in case something goes wrong you can be able to restore your instance the way it was initially.

  • Go to your EC2 instances dashboard, click on the instance you intend to modify 
  • Select Actions from the option, click on Image and template from the options 
  • Select Create Image  
  • Give it a name and a detailed description. 
  • Click create image, you might have to drag your screen slightly to the right to see that option. 

I explained in more detail in this article what EC2 images, snapshots, volumes are and how to use them.

  • Create an SSH connection to your EC2 instance. If you don’t know how to do that yet, check out how to connect to your EC2 instance through SSH
  • Switch the user to admin, which you can do through the command su root It requests that you create your new password. Create your new password, and continue.
  • Run the command su root to log in as admin if not logged in as admin.
change linux server root password

When I encountered this issue, I discovered that a part of the problem was because I was running two servers on my instance; Apache and Nginx, both servers would demand access to port 80 of my EC2 instance which one would fail, usually Apache.

Apache runs my WordPress instance which means I would need to keep it and remove Nginx from my instance. 

Note: The commands I give below are what worked for my instance Debain distro, you can check for similar commands for other instance types like CentOS. 

Follow the commands to uninstall nginx and restart the server. If you don’t have two servers running on your instance then skip this part, you don’t have to uninstall anything.

  • Stop the nginx server from running. See the command below.    sudo systemctl stop nginx 
  • Remove all nginx packages.  sudo apt-get remove nginx 
  • Purge nginx configuration files.  sudo apt-get purge nginx 
  • Clean up what’s left.  sudo apt-get autoremove 
remove nginx from server

After uninstalling nginx, you can now reinstall, update, and restart Apache.

  • Update the environment and dependencies.    sudo apt update 
  • Install or update Apche2
    sudo apt install apache2
    sudo apt update Apache2 
  • Restart your Apache server.  sudo systemctl restart apache2 
  • Get the status of Apache running now,  sudo systemctl status apache2

At this point Apache should be set up and currently running for which it will show active as shown in the screenshot below. 

server status of apache

If Apache restart failed, check out the error log for Apache below and try the other commands below to figure things out.     sudo journalctl -u apache2.service --since today --no-pager 

Check back at your instance, try accessing the webpage using the domain you registered for it or the public IPV4 address attached to it. 

If you still could not access the webpage, other things could still cause this. Follow the instructions to fix it.

  • Reboot the system, this means you must connect to the system again and log in as admin      sudo reboot 
  • Confirm the Apache configuration file, you should receive the response syntax ok.    sudo apachectl configtest 

    configuration test of 
 apache
  • Reload the server    sudo systemctl reload apache2.service 
  • Confirm Apache is using the correct ports, run the command below, and you should see that Apache is running on various PID  
    sudo ss -4 -tlnp | grep 80
    sudo ss -6 -tlnp |grep 80 
  • Confirm Apache is running again when you run the command below. You should see that Apache is active and running. If Apache isn’t running or active, you should try restarting, reinstalling, or reloading Apache as given in the above commands.    sudo systemctl status apache2 
apache server status checker

Check back at your instance, try accessing the webpage using the domain you registered for it or the public IPV4 address attached to it.

If your webpage isn’t loading, then you might want to switch from running Apache in those ports to running httpd.  

HTTPD stands for HyperText Transfer Protocol Daemon. It is the Apache Hypertext Transfer Protocol (HTTP) server program. Apache HTTP Server, often referred to simply as Apache, is a free and open-source web server software. 

Follow the instructions to switch your port to HTTPD.

  • Run the command below to check If HTTPD is running on any port, you will get a response could not bind to response 0.0.0.0:80 sudo /opt/bitnami/apache/bin/httpd 
  • Run the command below to confirm the applications using the required port.   sudo ss -6 -tlnp |grep 80 
  • Kill all the processes using the required ports with the kill command and the PID of the process, usually a number. Replace PID with the PID of the programs.   sudo kill  <PID1>  <PID2>   <PID3> 
  • Start HTTPD with the command below.   sudo /opt/bitnami/apache/bin/httpd 
  • Confirm HTTPD now runs on the required ports      sudo ss -6 -tlnp |grep 80
enable httpd over apache to get your website up again

Check back at your instance, and try accessing the webpage using the domain you registered for it or the public IPV4 address attached to it. Your website should come up about now.

Enter exit to exit your EC2 terminal, you might need to enter it twice to exit fully considering you are connected as a root user.

Conclusion

If this method did not work for you, check out the resources where I used for myself when working on this. 

Check out:

https://www.digitalocean.com/community/tutorials/apache-network-error-ah00072-make_sock-could-not-bind-to-address

https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-apache-errors

Please share your comment, and check out other articles.

Please share this article at the top of the page under the share this button. Thanks

Recent Post

Send Us A Message

Related Post

Join our newsletter to stay updated

digitalspeed-logo

At DIGITALSPEED, you can get updates, reviews and learn about new digital tools and features on existing tools. check us on social media.

Get In Touch

Lagos, Nigeria

DIGITALSPEED © All Rights Reserved.

2025

Scroll to Top

Seach for Articles