Why is the characterset changing if starting Glassfish using php_exec compared to starting it in the console?

by Attila Antal   Last Updated October 09, 2019 23:00 PM - source

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!

Related Questions

enable-secure-admin not found

Updated June 30, 2016 08:00 AM

Glassfish crashes due too many open files

Updated August 01, 2018 15:00 PM

How can I install php53u-xml package (CentOS)?

Updated July 24, 2015 13:00 PM