Select Page

Introduction

Apache. The name no software guy is unfamiliar with. In the simplest of terms, it is the most widely used web-server for running and maintaining websites on the Internet. It is responsible for directing users on the internet to the desired HTTP directory. Given that it’s so popular, it still stands on its name while being free and open-source. How cool is that?

Despite how cool it sounds, I’m about to tell you something dreadful. With popular programs come popular error messages, and one such is the “failed to start apache http server” message. Don’t be disheartened just yet! Because the fix itself is way easier than running the server itself. If you can get your guts to run the server, you can fix the problem like so. All it takes is just a bit of understanding! 

In this article, we’ll try to break down the possible causes for encountering this error message, and provide you with their fixes all along.


Possible causes for ‘failed to start the apache http server’

No directory present for Apache Log files

The first possible reason for the failure of starting the apache http server is due to the absence of the log file directory for apache. Log files are extremely crucial for server management tools, which is why not having this directory straight out means that the apache server will be unable to run. This directory should usually be created automatically when you install apache. 

In many cases, it is possible that a disk-cleanup utility may have removed those log files, stating them as unnecessary. There sure are programs that have faint use of log files, but it isn’t the same for server management tools. Which is why you will need to create that directory.

Port is already occupied

The other very, very common reason for the error message to occur is that some other program is already occupying the same port, which apache is trying to use. The default port that apache tries to use is 80, but apache is not alone. Other tools like nginx also use the port 80 by default. This is because 80 is actually the default port for HTTP itself. 

Therefore, in order for apache to run, you either need to remove the program which is occupying port 80, or change the port of either apache or the other program so as to avoid conflicts and start the server smoothly.


How to fix ‘failed to start the apache http server’

Restart the Apache Server

The first thing you’d like to do before anything else is to see if restarting the apache server works out. This could help out in certain cases, and for many could turn out to be the only fix they require to abolish the error message. The best way to do this is to fully stop the server and than start it again, rather than using restart command:

$ sudo systemctl stop apache2.service 
$ sudo systemctl enable apache2.service 
$ sudo systemctl start apache2.service

If you don’t encounter any error while trying to use the above commands, then you have properly started the apache http server without any further errors. Also, notice the fact that I wrote apache2 instead of just apache. This is because the latest version of apache is above 2, so the service name has now changed to apache2 as well. If you’re using an older version, it is probably a good idea to switch. If you don’t want that, then make sure to type apache.service instead of apache2.service in the above commands. 

If the above hasn’t worked for you, try out the other methods that are discussed below. 

Create the directory for log files

As mentioned previously, not having the directory where the log files for apache are saved means that you’ll not be able to start the apache server. To fix this, simply create the directory by running:

$ mkdir -p /var/log/apache2

This should create the directory you’re looking for. However, if you’re using this command as a different user other than root, you’d see that the terminal is giving an output saying “permission denied”. Which is why, you will first need to login to the root user. Or else, you can also use the sudo command before to give superuser privileges to your current user. Try running the below command:

$ sudo mkdir -p /var/log/apache2

Now try starting the apache server once again to see if it works, by running:

$ sudo systemctl start apache2.service

If you see no error messages this time around, then you’ve successfully surpassed the error message! If fortune did not turn out to be true, and you still see errors, it probably means that this is not the issue, or at least, not the only issue. 

Stop/remove the program occupying the port

There are several ways to look into this solution for fixing the error message. The goal of this is to free up port 80 so that Apache can use it to run the server. But first, you need to figure out which program is actually occupying port 80. To do this, install a program called net-tools. If you’re using Ubuntu: you’d use the following command:

$ sudo apt-get install net-tools

Once the tool is installed, run the below command to see which program is occupying port 80:

$ sudo netstat -antup | grep 80

For example, look what I found in my case:

In the above image, I can see that port 80 is being occupied by the nginx server. So there are two things I could do to remove it’s occupation:

  1. Remove the Program entirely
  2. Disable it for a certain period
  3. Change the port for Apache

The choice is for you to make, for yourself. But I’ll show you all three.

The first option is to remove the program entirely. If you think that you don’t actually need the other program which is being used, you can remove it, by first figuring out its name like I did previously using the netstat command, and then use your package manager. In my case, it was nginx, so I’d use the following command to remove it:

$ sudo apt-get --purge remove nginx

Now try starting the apache server once again to see if it has worked out for you.

The next option is to disable the other program, for now at least. If you think you need to use both, at different intervals, then you can disable and enable the servers according to your demand. But if you wish to run them simultaneously, then you’ll need to change the port of at least one of the programs. For now, I’ll use the following commands respectively to disable nginx, to free up port 80:

$ sudo systemctl stop nginx 
$ sudo systemctl disable nginx

Once I’ve disabled it, now look what happens when I try out the netstat command once again:

$ sudo netstat -antup | grep 80

As you’d have probably noticed by now, the command returns you no output, as there is no program occupying port 80 at present.

Simple start the apache server now by running:

$ sudo systemctl start apache2.service

You should now successfully be able to start the apache http server without any further issues. 

There’s one last option that I’m left to show you, that is, to change the port for Apache. Though nor recommended, you can do this to run different servers at the same time, in case you need them all. 

Change the port for Apache

To change the port for Apache, first stop the apache server, bu running:

$ sudo systemctl stop apache2.service

Then, open up the ports.conf file using a text editor like nano, by using:

$ sudo nano /etc/apache2/ports.conf

inside this file, change the number 80 after listen to the port number you like. here, I’d like to use 8080, which should look something like this:

Once you’ve edited this file, you also need to make changes to the 000-default.conf file, located under the sites-enabled directory, so that the websites can recognise this new port. Open the file by running:

$ sudo nano /etc/apache2/sites-enabled/000-default.conf

Inside this file, you’d need to change the very first line, and change the number 80 to the new port, which in my case is 8080. After being changed, it should something like the one below:

After everything is set, try starting the server once again too see if the changes have taken effect:

$ sudo systemctl start apache2.service

This time around, if you use the same netstat command as previous, this is what you should be seeing if the changing was a success:

$ sudo netstat -antup | grep 80

Wala! Changing the port was a definite success! Now let’s take things to the minimal-extreme by checking if we can run nginx along with this server, both together. Once I start the nginx server once again, and when I ran netstat, look what I found:


Conclusion

Wohoooo! We now have both the servers up and running, without any conflicts, as well as without any error messages! As always, the choice is yours. If you think you need both of the servers, then using this method should probably be the correct way to do so. Otherwise, if you think that you only need apache, then taking this method is probably quite meaningless. But beware! It is also possible that some other application you’re running needs the other server to be run as well. So make sure you don’t remove it before clarifying that!