How to change charset=ISO-8859-1 to charset=UTF8? Rocky 9.1 server

Hi ! Everyone, I am back here to ask environmental issue.
When I ran the following testing script before placing at /var/www/cgi-bin, but it is still at /home/mkido/bin. Perl script ran successfully at the Terminal, and replied back the OUTPUT below there.

Perl Script,
#!/usr/bin/env perl
use strict;
use warnings;
use CGI;

my $q = CGI->new;
print $q->header();
print "OK";

mkido@localhost$ [Enter to run it.]
Content-Type: text/html; charset=ISO-8859-1


This output result evoked my recognition. Is this Rocky 9.1 Web Server running to provide charset=ISO-8859-1 ?? I want to set all replies from the Server to charset=UTF-8. The httpd.conf is already set to charset=UTF-8. Is there any other setting adjustment somewhere in environmental configuration on my server to change from charset=ISO-8859-1 to charset=UTF-8 ?? Thanks, thanks.


I would assume that the Perl CGI module is so old it defaults to latin-1. A quick glance at the docs confirms this:

"The -charset parameter can be used to control the character set sent to the browser. If not provided, defaults to ISO-8859-1."

So you'll need to tell explicitly to use utf8 via $cgi->header(-charset => 'utf-8') AND make sure the content is correctly encoded.

That being said, I would not use plain but look into Plack/PSGI instead (which has a CGI compat mode).

Yes, at least there are multiple posts using images etc

Leave a comment

About Kido Mitsuru

user-pic To ask questions to this blog community