0

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).

4
  • for starting apache2, you should write <code>sudo service apache2 start</code> Mar 24 '17 at 12:46
  • Does not work, either. Mar 24 '17 at 12:51
  • You can see the same problem in link Mar 24 '17 at 13:02
  • @TarunkantGupta: I used lowercase letters Mar 24 '17 at 13:11
3

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
5
  • Does mysite.conf go under /etc/apache2/sites-available/, too? Can I use another name instead? Mar 24 '17 at 14:00
  • Yes. For convenience call the mysite the name of what you want your site to be called when accessing it. For instance, apollo3.conf... or anything else. And yes... the virtualhost files goes in the /etc/apache2/sites-available folder. Mar 24 '17 at 14:03
  • Apparantly, the first time I apt-get installed apache2 something went wrong. This time, I seem to have all the needed files. Thanks for showing how to uninstall my previous broken installation. Mar 24 '17 at 14:11
  • Always a pleasure! Mar 24 '17 at 14:12
  • You may also need to edit /etc/hosts and add the name you set for ServerName, as well as setting the right Directory permissions in the .conf file, AND making the www-data group own your application files... See digitalocean.com/community/tutorials/…, cyberciti.biz/faq/apache-403-forbidden-error-and-solution, and stackoverflow.com/questions/5246114/… (: Jun 25 '18 at 4:46
0

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.

1
  • This is what I think, too: there should be a minimal apache2.conf file. Mar 24 '17 at 12:57
0

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 http://127.0.0.1:80. 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
2
  • I don't have an /etc/init.d/apache2 file (or script). Mar 24 '17 at 13:53
  • @RenéNyffenegger That's an indication that Apache2 isn't installed properly. Mar 24 '17 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.