4

When trying to install new letsencrypt certificates on my raspberry-pi apache 2.4 webserver using sudo certbot --apache I get the following error:

Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.

apache2: Syntax error on line x of /etc/apache2/apache2.conf: Syntax error on line x of /etc/apache2/sites-enabled/xxx-le-ssl.conf: Expected </VirtualHost> but saw </VirtualHost></IfModule>

How can this error be fixed?

dargmuesli
  • 181
  • 6

1 Answers1

4

Thanks to the letsencrypt community I found a simple solution.

The error originates from missing newlines at the end of each enabled (apache) site. So you either add them to each file in sites-enabled or 'sites-available' (both usually located in /etc/apache2/) or you can use Yanson's one liner:

for f in /etc/apache2/sites-available/*; do sed -i '$a\' "$f"; done

dargmuesli
  • 181
  • 6
  • For people who use other Linux distros who have this issue: Make sure that the site config file in /etc/httpd/conf.d has a carriage return/new line after the last – uncovery Feb 15 '17 at 06:29