15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPでexecを走らせると日本語だけ消える

Posted at

#概要
新入社員として色々お仕事を手伝わせて頂いている中、頭には学校の研究があるどうしようもないクズですごめんなさい。
入社して3ヶ月経って自宅サーバなどが整いつつあるので、その時にハマった事について少し書きます。
今回は「PHPでexecを走らせると日本語だけ消える」件についてです。

#原因
単純な話、CentOSを英語圏のロケール設定でインストールするとapacheやphpなど様々なアプリケーションが英語圏の設定になってしまい、日本語を扱う場合は宣言しないとダメです。
特にPHPのexecを使う場合、PHPのシェル関数「escapeshellcmd」「escapeshellarg」を使うと想いますが、これはphp.iniの他に「/etc/sysconfig/httpd」に「HTTPD_LANG=ja_JP.utf8」の記述が必要です。
設定がされていない場合、マルチバイト文字は切り捨てられます。

##変更点

/etc/sysconfig/httpd

# Configuration file for the httpd service.

#
# The default processing model (MPM) is the process-based
# 'prefork' model.  A thread-based model, 'worker', is also
# available, but does not work with some modules (such as PHP).
# The service must be stopped before changing this variable.
#
#HTTPD=/usr/sbin/httpd.worker

#
# To pass additional options (for instance, -D definitions) to the
# httpd binary at startup, set OPTIONS here.
#
#OPTIONS=

#
# By default, the httpd process is started in the C locale; to
# change the locale in which the server runs, the HTTPD_LANG
# variable can be set.
#
#HTTPD_LANG=C
HTTPD_LANG=ja_JP.utf8 # 日本語対応

#
# By default, the httpd process will create the file
# /var/run/httpd/httpd.pid in which it records its process
# identification number when it starts.  If an alternate location is
# specified in httpd.conf (via the PidFile directive), the new
# location needs to be reported in the PIDFILE.
#
#PIDFILE=/var/run/httpd/httpd.pid
15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?