Changing the www-data User Environment for a Perl Script

Written by James McDonald

September 1, 2018

The Problem – Rendering Unicode Characters using Glabels

I have a Perl script running on an Apache webserver that launches glabels-3-batch and given a data input file and a glabels template outputs a label as a PDF document.

This is in a Ubuntu 18.04.1 LTS container running on Docker Community Edition on my MacBook Pro

The problem is that I have been using a $Latex \beta $  (beta) character in the file and when running from the command line with a UTF-8 language configured (en_AU.UTF-8) it works fine…

But from a web server, which is running as the www-data user the line with the $Latex \beta $ (beta) value in it is missing…

I’ve traced the problem to not having a LANG environment variable specified in the environment that the www-data user is running under.

What doesn’t work

I tried adding
PerlSetEnv LANG en_AU.UTF-8
to /etc/apache/apache2.conf
I also tried adding 
export LANG=en_AU.UTF-8
to /etc/apache/envars
But both of the above didn’t add the LANG setting to the environment

The Fix

To test the environment I used this script placed at cgi-bin/

What worked was adding
SetEnv LANG en_AU.UTF-8
to /etc/apache/apache2.conf

Viewing your mod_perl / CGI Environment

#!/usr/bin/perl -wT
use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

print header;
print start_html("Environment");

foreach my $key (sort(keys(%ENV))) {
    print "$key = $ENV{$key}<br>\n";


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

PHPSECLIB3 Client Algorithms

Recently our EDI supplier notified that they were changing their SFTP encryption and data integrity algorithms I use...