Chris Mendez in AWS, Lightsail, DevOps

Fixing Apache "Address already in use" error

AWS Lightsail allows you to quickly make snapshots from your LAMP stack and deploy them later. If you one day decide to create a new instance of your snapshot and you happen to have an SSL certificate within your Apache config, you may see this error.

(98) Address already in use: make_sock: could not bind to address

This error means that Apache cannot start because your SSL certificate needs a password. Here's how to fix it:

Step 1 - Find the process that's hanging

There are a lot of different ways to do this. Here are a few:

Method 1: Use grep.

grep -ri listen /etc/apache2

Method 2: Use process then filter it with grep.

ps -ef | grep apache

If you see something like this, proceed to step 2.

Method 3: Use netstat and filter with grep.

sudo netstat -ntlp | grep 80

If you see something like this, you've found it! In the screen show below, the culprit is a process with an id (pid) of 1666.


Method 4: Show processes hung

ps wax | grep httpd


Step 2 - Kill those processes

sudo kill -9 process_id

Step 3 - Double Check Your Work

ps -ef | grep apache