I have created a PHP script to start/stop GlassFish server. In the PHP, I am using the shell_exec method to execute the start-domain and stop-domain commands.

To start the server

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin start-domain domain1");

To stop the server

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin stop-domain domain1");

While the script does start and stop the server, there is an issue I can't figure out. The character encoding changes to something different and the special characters coming from the client requests are no longer formatted correctly.

Characters with correct charset

enter image description here

Characters with incorrect charset

enter image description here

Seems that the settings for UTF-8 are getting ignored and it falls back to a different charset what I believe to "ISO-8859-1".


<jdbc-connection-pool connection-validation-method="auto-commit" ...>
  <property name="characterEncoding" value="UTF-8"></property>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <class-loader delegate="true"/>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class java code.</description>
  <!-- Change the default character encoding from ISO-8859-1 to UTF-8 -->
  <parameter-encoding default-charset="UTF-8"/>

During my investigation I found numerous articles stating to define the character set in the sun-web.xml (older version of glassfish - my case) but does not help.

After some testing, I have noticed that if I login with www-data in the console, the default shell used is /bin/sh and starting the domain from that causes the same issue. However, if I switch to /bin/bash, then it works.

Does anyone have a clue what could be the difference?

Any information on this will be much appreciated!

  • 1
    It'll be environment differences, probably LANG. – womble Oct 9 at 23:22

Apparently the shell locale has an impact on how the GlassFish server interprets requests. I don't find it logical since the domain has its own settings file for that...

The following user comment actually helped: shell_exec

$locale = "en_US.UTF-8";
setlocale(LC_CTYPE, $locale);
putenv('LC_CTYPE=' . $locale);

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin start-domain domain1");

It works like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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