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?

1 Answer 1


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

  • 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 </VirtualHost>
    – uncovery
    Feb 15, 2017 at 6:29

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.