Error Running Client: Expected </VirtualHost> but saw </VirtualHost></IfModule>

I fixed this by putting a newline at the end of the conf file.


As said by @Konrad90, adding a newline to the end of each file fixed this issue for me.

newline fixed the issue. Thank You!

Fixed adding the new line as suggested. Here’s a one-liner:

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


1 Like

Just add an empty line at the end of your .conf file into the directory sites-available/

Thank You!
one newline at bottom fix this!

Thanks from me too, newline sorted it, now on to the next issue in my slightly sketchy apache setup, all sites appear to redirect to one default :stuck_out_tongue:

Just created an account here to confirm that the newline solved this for me as well. I would have never found this myself, so thanks a lot!

Since a stand-alone apache config test does not report such a syntax error, does that mean that the letsencrypt certbot is overly sensitive to it?

Yes, it is too sensitive.

I created a new file /etc/apache2/sites-available/my.domain.conf and then I was facing similar problem with configtest as cray or groovyben008 did: not matched and tags, although visually they looked OK.
It was caused by three garbage bytes - UTF-8 BOM - which my editor had put in front of . Theese bytes are invisible in most text viewers and Apache conf parser isn’t smart enough to ignore them.
So if configtest reports inexplicable error, look at the file with hexa viewer xxd.

  1. I fixed this problem just creating a file (replace with your domain) in /etc/apache2/sites-available/



DirectoryIndex index.html index.php
DocumentRoot /var/www/html/

LogLevel warn
ErrorLog /var/www/html/
CustomLog /var/www/html/ combined

  1. Then run the command certbot