Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Apache server on a Debian machine,

I also have PHP installed on it, there are some bad characters, shown on all sites that are hosted on that machine.

For example instead of


it shows


I think this is probably an Apache issue because the same code and database works perfectly elsewhere, I'm not absolutely sure though, so what kind of things would I have to do to fix this?

share|improve this question
Are these characters in static files, or dynamic content served from PHP? Apache doesn't involve itself in character encoding within documents, so the odds that it's at fault are pretty small; you'll want to look instead at your code, PHP's character encoding settings, and the database's character encoding settings. – Shane Madden Jan 9 '12 at 21:22
It would be interesting if these bad characters are not in the source code and only appear randomly on the rendered page. – Tim Jan 9 '12 at 21:25
They are coming from the database, they are not in static files, and they are not appearing randomly I think it's every instance that comes from db – user893730 Jan 9 '12 at 21:35
up vote 1 down vote accepted

Looks like something is wrong with the character encoding. A few things you can try:

Have you tried setting the charset of your HTML output explicitly to match the charset of your database?For example, if your database has UTF-8, try declaring it in a meta tag inside de <head> tags:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 

For HTML 5 it is far shorter:

<meta charset="UTF-8" />

For mysql, you can figure out which character set your db is using by executing the following statements:

USE <databasename>;
SHOW VARIABLES LIKE 'character_set_database';

Other DBMS will have similar statements.

However, I don't think you need to repeat this for every page/site (but it certainly doesn't hurt if you do): It is of course easier to change Apache's default charset adjusting the AddDefaultCharset directive in httpd.conf or apache2.conf or wherever your main configuration is located:

# AddDefaultCharset Somethingelse
AddDefaultCharset UTF-8

Reload apache afterwards.

share|improve this answer
Thank you for the comprehensive response, it can't be the page encoding since it works everywhere else, this must be a server config issue, the mysql returned latin1 as to the response of your query, I also added the apache config directive, it didn't make a difference. – user893730 Jan 10 '12 at 22:11
Apperently there is also a php.ini variable: default_charset = "UTF-8", or in this case latin1. Worth a try =) – Filipe Spencer Jan 11 '12 at 23:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.