Ubuntu: How do I install and start apache2


I am trying to install and run apache2.

So I did

sudo apt-get install apache2  sudo apt-get install apache2-utils  

And then tried to start it

sudo apache2  

which was answered with

apache2: Could not open configuration file /etc/apache2/apache2.conf: No such file or directory  

This is in fact true: there is no such file.

So I touched it:

sudo touch /etc/apache2/apache2.conf  

and tried again

sudo apache2  

which is now answered by

AH00534: apache2: Configuration error: No MPM loaded.  

Very probably, I should add something to the touched /etc/apache2/apache2.conf file. But I have no idea what.

So, I have at least three questions: is apache supposed to be started with sudo apache? And what is the minimal configuration that I have to put into the apache2.conf file? Is there a package that I can apt-get install with such a minimal configuration to work from there?

Addendum As per Tarunkant Gupta's comment, if I try to start apache with

sudo service apache2 start  

I get

Failed to start apache2.service: Unit apache2.service not found.  

As per Saragyal's answer: I don't have /etc/apache2/sites-available nor /etc/apache2/sites-enabled. The content of /etc/apache2 is:

tree /etc/apache2  /etc/apache2/   â"œâ"€â"€ apache2.conf   â""â"€â"€ conf-available      â""â"€â"€ javascript-common.conf  

(and apache2.conf stems from my touching it).


Since you don't have Apache installed and functionally working, you don't need the /etc/apache2 directory where all the configuration files are stored.

You also mentioned that you used touch to create an apache.conf file. That is very problematic because there are defaults and settings that need to be specified in the conf file, which is missed by creating a blank file.

Apache will work when installed from the repository. It will create all the necessary files and actually start the server when installed.

Remove what you have, then perform a fresh install from the repository.

Remove and purge the current installation:

$ sudo apt-get remove --purge apache2 libapache2-mod-php  $ sudo apt autoremove  $ sudo apt-get remove --purge apache2 libapache2-mod-php   

You may have to cycle through those two commands more than once. It'll be clean when the last command's output resembles:

apollo@testnode2:~$ sudo apt-get remove --purge apache2 libapache2-mod-php  Reading package lists... Done  Building dependency tree         Reading state information... Done  Package 'libapache2-mod-php' is not installed, so not removed  Package 'apache2' is not installed, so not removed  0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.  

Now remove faulty configuration files that may not be overwritten in a fresh install. Remove or rename the /etc/apache2 folder:

$ sudo mv /etc/apache2/ /etc/apache2.old  

Now install Apache2 fresh with:

$ sudo apt-get install apache2 libapache2-mod-php  

If you have settings from your old settings that you want to incorporate into the new installation, you can copy the difference to the new /etc/apache2 directory. Making step-by-step changes might help you to identify where you went wrong the first time.

Put your site's configuration files into a VirtualHost

Also, I recommend that you leave the /etc/apache2/sites-available/000-default.conf file intact. Make a new virtual host file to contain your desired configuration. Just copy the 000-default.conf to a mysite.conf file, then enable this virtual host with the command:

$ sudo a2ensite mysite.conf  

This way if there is a problem with your configuration file, you can just disable it with a2dissite mysite.conf while you fix it. Apache won't be broken in the meantime. You'll also retain the 000-default.conf as a template for a working reference.

The key to a virtualhost configuraiton is the ServerName directive. Accessing your site by that name will call that specific configuration.

Starting, Stoping, and checking the Apache2 server

You shouldn't try to start the Apache2 server by running the /usr/bin/apache2 command. The server should be started with a script to set all the needed variables.

You can start, stop, and check the status of the Apache2 server with one of these commands:

$ sudo systemctl stop apache2  $ sudo systemctl start apache2  $ sudo systemctl status apache2  


It's odd that there is no apache2.conf file. Just google "default apache2.conf" and you should find a file on top. Just to confirm is there a chance you also dont have virtual sites. Check contents of directory /etc/apache2/sites-available and /etc/apache2/sites-enabled.

P.S. I couldn't comment.


You install Apache using this command:

$ sudo apt-get install apache2 -y  

When the installation process is finished, Apache should be started automatically. Check whether your Apache server is running using this command:

$ /etc/init.d/apache2 status  

If you see something like the following (specifically, the green circle indicating that the Apache is running), you're good to go:

enter image description here

Now, test it. Open up your web browser and navigate to the address If you see the Apache default page, your server is up and working.

To stop Apache, use this command:

$ sudo /etc/init.d/apache2 stop  

To start Apache, use this command:

$ sudo /etc/init.d/apache2 start  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »