apache2 won't start due to syntax error in config file

Asked by apsaras

Ubuntu 20.04.3 LTS.

Clean install of apache2 (version 2.4.41-4ubuntu3.8 amd64)

apache2 won't start due to syntax error in config file, but I can't see the error.

Steps to reproduce:

sudo apt-get purge apache2
rm -r /etc/apache2
sudo apt-get install apache2

Expected to see: error-free start

What happened:
...
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
invoke-rc.d: initscript apache2, action "start" failed.
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2021-12-04 10:48:59 GMT; 10ms ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3059008 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Dec 04 10:48:59 mycomputer systemd[1]: Starting The Apache HTTP Server...
Dec 04 10:48:59 mycomputer apachectl[3059021]: apache2: Syntax error on line 147 of /etc/apache2/apache2.conf: Syntax error on line 22 of /etc/apache2/mods-enabled/alias.conf:
Dec 04 10:48:59 mycomputer apachectl[3059008]: Action 'start' failed.
Dec 04 10:48:59 mycomputer apachectl[3059008]: The Apache error log may have more information.
Dec 04 10:48:59 mycomputer systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Dec 04 10:48:59 mycomputer systemd[1]: apache2.service: Failed with result 'exit-code'.
Dec 04 10:48:59 mycomputer systemd[1]: Failed to start The Apache HTTP Server.
...

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu apache2 Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

What is the output of the command

cat -n /etc/apache2/mods-enabled/alias.conf

?

Revision history for this message
apsaras (xbuntuone) said :
#2

     1 <IfModule alias_module>
     2 # Aliases: Add here as many aliases as you need (with no limit). The format is
     3 # Alias fakename realname
     4 #
     5 # Note that if you include a trailing / on fakename then the server will
     6 # require it to be present in the URL. So "/icons" isn't aliased in this
     7 # example, only "/icons/". If the fakename is slash-terminated, then the
     8 # realname must also be slash terminated, and if the fakename omits the
     9 # trailing slash, the realname must also omit it.
    10 #
    11 # We include the /icons/ alias for FancyIndexed directory listings. If
    12 # you do not use FancyIndexing, you may comment this out.
    13
    14 Alias /icons/ "/usr/share/apache2/icons/"
    15
    16 <Directory "/usr/share/apache2/icons">
    17 Options FollowSymlinks
    18 AllowOverride None
    19 Require all granted
    20 </Directory>
    21
    22 </IfModule>
    23
    24 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

What is the output of

ls -l /etc/apache2/mods-enabled/

Revision history for this message
apsaras (xbuntuone) said :
#4

(Anything in /etc/apache2 should be unmodified, because I removed it all before reinstalling.)

$ ls -l /etc/apache2/mods-enabled/
total 0
lrwxrwxrwx 1 root root 36 Dec 4 10:48 access_compat.load -> ../mods-available/access_compat.load
lrwxrwxrwx 1 root root 28 Dec 4 10:48 alias.conf -> ../mods-available/alias.conf
lrwxrwxrwx 1 root root 28 Dec 4 10:48 alias.load -> ../mods-available/alias.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 auth_basic.load -> ../mods-available/auth_basic.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 authn_core.load -> ../mods-available/authn_core.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 authn_file.load -> ../mods-available/authn_file.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 authz_core.load -> ../mods-available/authz_core.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 authz_host.load -> ../mods-available/authz_host.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 authz_user.load -> ../mods-available/authz_user.load
lrwxrwxrwx 1 root root 32 Dec 4 10:48 autoindex.conf -> ../mods-available/autoindex.conf
lrwxrwxrwx 1 root root 32 Dec 4 10:48 autoindex.load -> ../mods-available/autoindex.load
lrwxrwxrwx 1 root root 30 Dec 4 10:48 deflate.conf -> ../mods-available/deflate.conf
lrwxrwxrwx 1 root root 30 Dec 4 10:48 deflate.load -> ../mods-available/deflate.load
lrwxrwxrwx 1 root root 26 Dec 4 10:48 dir.conf -> ../mods-available/dir.conf
lrwxrwxrwx 1 root root 26 Dec 4 10:48 dir.load -> ../mods-available/dir.load
lrwxrwxrwx 1 root root 26 Dec 4 10:48 env.load -> ../mods-available/env.load
lrwxrwxrwx 1 root root 29 Dec 4 10:48 filter.load -> ../mods-available/filter.load
lrwxrwxrwx 1 root root 27 Dec 4 10:48 mime.conf -> ../mods-available/mime.conf
lrwxrwxrwx 1 root root 27 Dec 4 10:48 mime.load -> ../mods-available/mime.load
lrwxrwxrwx 1 root root 32 Dec 4 10:48 mpm_event.conf -> ../mods-available/mpm_event.conf
lrwxrwxrwx 1 root root 32 Dec 4 10:48 mpm_event.load -> ../mods-available/mpm_event.load
lrwxrwxrwx 1 root root 34 Dec 4 10:48 negotiation.conf -> ../mods-available/negotiation.conf
lrwxrwxrwx 1 root root 34 Dec 4 10:48 negotiation.load -> ../mods-available/negotiation.load
lrwxrwxrwx 1 root root 33 Dec 4 10:48 reqtimeout.conf -> ../mods-available/reqtimeout.conf
lrwxrwxrwx 1 root root 33 Dec 4 10:48 reqtimeout.load -> ../mods-available/reqtimeout.load
lrwxrwxrwx 1 root root 31 Dec 4 10:48 setenvif.conf -> ../mods-available/setenvif.conf
lrwxrwxrwx 1 root root 31 Dec 4 10:48 setenvif.load -> ../mods-available/setenvif.load
lrwxrwxrwx 1 root root 29 Dec 4 10:48 status.conf -> ../mods-available/status.conf
lrwxrwxrwx 1 root root 29 Dec 4 10:48 status.load -> ../mods-available/status.load

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

I just used a test system to install apache2 and it worked without problems.

If you want to do further diagnostics, then I suggest the following:

sudo apt purge apache2
sudo apt --purge autoremove # to uninstall also apache2-bin, apache2-data etc.

and then

sudo apt install apache2

What is the full output of the install command?

Revision history for this message
apsaras (xbuntuone) said :
#6

Thank you very much for going to the trouble of testing that.

Unfortunately it still doesn't work for me. In fact I removed some other packages too to match the intention of your comment ("# to uninstall also apache2-bin, apache2-data etc.").

sudo apt purge apache2 apache2-bin apache2-data apache2-utils
sudo apt --purge autoremove
sudo apt install apache2

but it still breaks with the same syntax error:

Dec 07 20:08:06 mycomputer apachectl[3381397]: apache2: Syntax error on line 147 of /etc/apache2/apache2.conf: Syntax error on line 22 of /etc/apache2/mods-enabled/alias.conf:

There is obviously something messed up with some other aspect of my system. If you have time, could you possibly give me a hint on how to start investigating what it might be? E.g., are there other Debian packages that relate to alias_module?

Revision history for this message
apsaras (xbuntuone) said :
#7

Sorry, you asked for full output:

$ sudo apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libaprutil1-dbd-sqlite3 libaprutil1-ldap
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed
  apache2 apache2-bin apache2-data apache2-utils libaprutil1-dbd-sqlite3 libaprutil1-ldap
0 to upgrade, 6 to newly install, 0 to remove and 5 not to upgrade.
Need to get 1,443 kB/1,538 kB of archives.
After this operation, 6,937 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-4ubuntu2 [10.5 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-ldap amd64 1.6.1-4ubuntu2 [8,736 B]
Get:3 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-bin amd64 2.4.41-4ubuntu3.8 [1,181 kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-data all 2.4.41-4ubuntu3.8 [159 kB]
Get:5 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-utils amd64 2.4.41-4ubuntu3.8 [84.5 kB]
Fetched 1,443 kB in 0s (11.6 MB/s)
Selecting previously unselected package libaprutil1-dbd-sqlite3:amd64.
(Reading database ... 384256 files and directories currently installed.)
Preparing to unpack .../0-libaprutil1-dbd-sqlite3_1.6.1-4ubuntu2_amd64.deb ...
Unpacking libaprutil1-dbd-sqlite3:amd64 (1.6.1-4ubuntu2) ...
Selecting previously unselected package libaprutil1-ldap:amd64.
Preparing to unpack .../1-libaprutil1-ldap_1.6.1-4ubuntu2_amd64.deb ...
Unpacking libaprutil1-ldap:amd64 (1.6.1-4ubuntu2) ...
Selecting previously unselected package apache2-bin.
Preparing to unpack .../2-apache2-bin_2.4.41-4ubuntu3.8_amd64.deb ...
Unpacking apache2-bin (2.4.41-4ubuntu3.8) ...
Selecting previously unselected package apache2-data.
Preparing to unpack .../3-apache2-data_2.4.41-4ubuntu3.8_all.deb ...
Unpacking apache2-data (2.4.41-4ubuntu3.8) ...
Selecting previously unselected package apache2-utils.
Preparing to unpack .../4-apache2-utils_2.4.41-4ubuntu3.8_amd64.deb ...
Unpacking apache2-utils (2.4.41-4ubuntu3.8) ...
Selecting previously unselected package apache2.
Preparing to unpack .../5-apache2_2.4.41-4ubuntu3.8_amd64.deb ...
Unpacking apache2 (2.4.41-4ubuntu3.8) ...
Setting up libaprutil1-ldap:amd64 (1.6.1-4ubuntu2) ...
Setting up libaprutil1-dbd-sqlite3:amd64 (1.6.1-4ubuntu2) ...
Setting up apache2-data (2.4.41-4ubuntu3.8) ...
Setting up apache2-utils (2.4.41-4ubuntu3.8) ...
Setting up apache2-bin (2.4.41-4ubuntu3.8) ...
Setting up apache2 (2.4.41-4ubuntu3.8) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
invoke-rc.d: initscript apache2, action "start" failed.
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2021-12-07 20:08:06 GMT; 8ms ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3381387 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Dec 07 20:08:06 mycomputer systemd[1]: Starting The Apache HTTP Server...
Dec 07 20:08:06 mycomputer apachectl[3381397]: apache2: Syntax error on line 147 of /etc/apache2/apache2.conf: Syntax error on line 22 of /etc/apache2/mods-enabled/alias.conf:
Dec 07 20:08:06 mycomputer apachectl[3381387]: Action 'start' failed.
Dec 07 20:08:06 mycomputer apachectl[3381387]: The Apache error log may have more information.
Dec 07 20:08:06 mycomputer systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Dec 07 20:08:06 mycomputer systemd[1]: apache2.service: Failed with result 'exit-code'.
Dec 07 20:08:06 mycomputer systemd[1]: Failed to start The Apache HTTP Server.
Processing triggers for systemd (245.4-4ubuntu3.13) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for ufw (0.36-6ubuntu1) ...

Revision history for this message
Manfred Hampl (m-hampl) said (last edit ):
#8

Have you already fully updated all other packages
sudo apt update && sudo apt full-upgrade

I assume that you get the same error message for the command

systemctl start apache2
and for
sudo apachectl start

Is that the case?

Revision history for this message
Manfred Hampl (m-hampl) said :
#9

What output do you receive for

apachectl configtest

Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#10

https://askubuntu.com/questions/679672/unable-to-load-mod-alias-in-apache

Try:

sudo mv /etc/apache2 /etc/apache2.bak
sudo apt-get purge apache2
sudo apt-get update
sudo apt-get install apache2

Then reboot

Revision history for this message
apsaras (xbuntuone) said :
#11

Manfred:
Thanks, but these produced the same error messages.

actionparsnip:
The 'mv' command didn't add anything new (I already did rm -r /etc/apache2) but rebooting fixed the problem!

My computer had been up for 140 days. Is it possible some package update during this time messed with mod_alias in a way that required a reboot? I wonder if there is a way to make this work better so other people aren't caught out like this (better error messages, or better updates?).

To both of you: thank you very much for all the help - very kind of you.

Revision history for this message
apsaras (xbuntuone) said :
#12

Thanks actionparsnip, that solved my question.

Revision history for this message
Manfred Hampl (m-hampl) said :
#13

Remark:

There are the files /run/reboot-required and /run/reboot-required.pkgs signalling if a reboot is necessary to fully install some packages. I do not think that it will be possible to retroactively find out if that was the case with your system.