Add and append text to a file

There are different ways, I like is:

echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn

append text to a file

echo "ServerName localhost-appended" | sudo tee -a /etc/apache2/conf.d/fqdn