1

I installed Apache 2 on ubuntu 19.04 desktop and was able to do a test access via localhost. I then discovered that the service was masked. I know how to unmask it, but I do not want to do so until I understand why it was masked and have corrected any error situation. How should I troubleshoot this situation? I am brand new to apache2. The output from systemctl is attached:

gossage@jgossage-XPS-8700:~$ sudo systemctl status apache2
● apache2.service
   Loaded: masked (Reason: Unit apache2.service is masked.)
   Active: inactive (dead)
Jonathan
  • 1,280
  • Have you upgraded Ubuntu, Apache2 or have you experienced failure starting the service before?. Have you made changes to Apache2 configuration which resulted in errors?... all this could result in the service getting masked. – Raffa Sep 28 '19 at 15:28
  • @Raffa I have definitely not upgraded the service and I was running with a vanilla configuration prior to adding local configuration. – Jonathan Sep 28 '19 at 15:31
  • How did you install Apache2 and from which repository? – Raffa Sep 28 '19 at 15:32
  • @Raffa I installed Apache via apt from the Canadian mirror. Actually some parts came from the local mirror and others from Ubuntu directly. I was using the default apt configuration. – Jonathan Sep 28 '19 at 15:34
  • all looks normal. Did you start the Apache2 service prior to checking the status. You need to start the service for the first time after installation, which seems to have started successfully as you were able to test it on localhost. So why not reboot and check the service status again with systemctl status apache2 before currying on with further steps. – Raffa Sep 28 '19 at 15:40
  • @Raffa The install process caused it to start automatically. I was able to use service apache2 status successfully. – Jonathan Sep 28 '19 at 15:44
  • Then, it is not masked. A masked service will not start! Please [edit] your question to add the output of systemctl status apache2 – Raffa Sep 28 '19 at 15:45
  • @Raffa I rebooted but as I expected the service was still masked. I think the next step is to unmask it and see what happens when apache starts. – Jonathan Sep 28 '19 at 15:49
  • Please add the output of cat /lib/systemd/system/apache2.service and the output of cat /etc/systemd/system/apache2.service if there is any – Raffa Sep 28 '19 at 16:02
  • @Raffa I tried to unmask the service, but it deleted it. I tried reinstalling apache2 but this did not help. The service no longer exists. – Jonathan Sep 28 '19 at 16:04

1 Answers1

1

It appears that you had an empty service file or you have a duplicate service file in /etc/systemd/system/. This will usually get masked.


Check if the file /etc/systemd/system/apache2.service exists. If so, remove it and proceed below.


Apache2 service file should exist in /lib/systemd/system/. Please check if the file /lib/systemd/system/apache2.service exists. If yes, check the content against this:

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl stop
ExecReload=/usr/sbin/apachectl graceful
PrivateTmp=true
Restart=on-abort

[Install]
WantedBy=multi-user.target

If not, create the file and copy and paste the above content to it. Then try to enable the service by running:

sudo systemctl enable apache2

If successful, reboot your system

Raffa
  • 32,237