How to Set Default Charset to UTF8 in Apache


set default charset to UTF8 in apache

It is essential to set the right character encoding for your website so that all pages render properly. Otherwise, it can lead to poor user experience. By default, Apache uses default charset of ISO-8859-1 which can be limiting for unicode characters. Here’s how to set default charset to UTF8 in Apache so that it serves all characters properly.

 

How to Set Default Charset to UTF8 in Apache

It is very easy to set the default character encoding in Apache web server. Here are the steps to set default charset to UTF8 in Apache.

 

1. Open Apache config file

Open Apache default config file in a text editor. You will find it typically at any of the following locations, depending on your Linux distribution:

  • /etc/apache2/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf

 


$ sudo vim /etc/apache2/httpd.conf

 

2. Set Default Charset to UTF8

Simply add the following line to your Apache config file


AddDefaultCharset utf-8

 

3. Restart Apache web server

Restart Apache web server to apply changes


$ sudo /etc/init.d/apache2 start [Debian or Ubuntu]
# sudo apachectl restart [RHEL, CentOS or Fedora]

 

4. Test default character encoding

Type the following command


$ wget --server-response -O /dev/null http://your_domain_or_server_ip

OR


$ curl -I http://your_domain_or_server_ip

Sample output:


HTTP/1.1 200 OK
Server: nginx
Date: Mon, 05 Nov 2018 16:42:51 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Whom: l2-com-cyber
Vary: Cookie
Last-Modified: Mon, 05 Nov 2018 16:38:02 GMT
Cache-Control: max-age=311, must-revalidate
X-Galaxy: Andromeda-1
X-Origin-Type: DynamicViaDAL

 

 

That’s it! Your Apache web server will use the default charset as UTF8.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!