X-Powered-By: PHP

表題のヘッダについて。

■ 環境

  • PHP 7.0.16
  • Apache httpd 2.4.25
  • Amazon Linux

■ X-Powered-By

WordPressで運用しているサイトを何の気なしに`httpstat`した時に下記の表記に気がついた。

$ httpstat https://www.example.com/
Connected to XXX.XXX.XXX.XXX:443 from 192.168.XXX.XXX:49893

HTTP/1.1 200 OK
Date: Mon, 03 Jul 2017 10:06:41 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: Apache
X-Powered-By: PHP/7.0.16
  :
$

X-Powered-By: PHP/7.0.16“が表記されてる。可能な限り隠したい。”php.ini“を下記のように編集して`httpd reload`した。

; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header).  It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
; http://php.net/expose-php
expose_php = Off

デフォルトでは”On“であった。

これにより”X-Powered-By“ヘッダは追加されなくなった。

以上。

■ 関連

httpstat

PHP7 Opcache

表題の件について。しばし触っていなかったPHP。サイト表示を速くしたいとの依頼から、”APC“を入れれば良いのでは?と思ったが最近は違うようだ。

■ 環境

  • PHP 7.0.16
  • Amazon Linux

■ apcu

APC“で検索してみると下記の結果を得られた。

$ sudo yum search apc
Loaded plugins: priorities, update-motd, upgrade-helper
================= N/S matched: apc ==================
apc-panel.noarch : APC control panel
apcu-panel.noarch : APCu control panel
apcu70-panel.noarch : APCu control panel for php 7.0
php-ZendFramework-Cache-Backend-Apc.noarch : Zend Framework APC cache backend
php-pecl-apc.x86_64 : APC caches and optimizes PHP intermediate code
php-pecl-apc-devel.x86_64 : APC developer files (header)
php54-pecl-apc.x86_64 : APC caches and optimizes PHP intermediate code
php54-pecl-apc-devel.x86_64 : APC developer files (header)
php55-pecl-apc.x86_64 : APC caches and optimizes PHP intermediate code
php55-pecl-apc-devel.x86_64 : APC developer files (header)
php55-pecl-apcu.x86_64 : APC User Cache
php55-pecl-apcu-devel.x86_64 : APCu developer files (header)
php56-pecl-apcu.x86_64 : APC User Cache
php56-pecl-apcu-devel.x86_64 : APCu developer files (header)
php70-pecl-apcu.x86_64 : APC User Cache
php70-pecl-apcu-devel.x86_64 : APCu developer files (header)
perl-Mail-IMAPClient.noarch : An IMAP Client API

  Name and summary matches only, use "search all" for everything.
$

apcu“?”u“とは何だ?と少々違和感を感じた。調べてみるとPHP5.5以降からAPCは”opcache + APCu“という組み合わせになったようだ。とりあえず何も考えずに”opcache“を入れることにした。

■ opcache

$ sudo yum search opcache
Loaded plugins: priorities, update-motd, upgrade-helper
================= N/S matched: apc ==================
php55-opcache.x86_64 : The Zend OPcache
php56-opcache.x86_64 : The Zend OPcache
php70-opcache.x86_64 : The Zend OPcache

  Name and summary matches only, use "search all" for everything.
$

これをインストールする。

$ sudo yum install php70-opcache

versionを確認すると表示された。

$ php -v
PHP 7.0.16 (cli) (built: Mar  6 2017 19:45:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.16, Copyright (c) 1999-2017, by Zend Technologies
$

設定ファイルも下記にあるようだ。

/etc/php-7.0.d/10-opcache.ini

以上。

PHPのversionをWEBサーバに記載しない

表題の通り。先日の続き。PHPのversionは出したくないのでこれも消したい。

■ 環境

  • PHP 7.0.14
  • Apache 2.4.25
  • Amazon Linux

■ 現状

$ curl -I https://www.example.com/
HTTP/1.1 200 OK
Date: Wed, 08 Feb 2017 10:15:44 GMT
Server: Apache
X-Powered-By: PHP/7.0.14
  :

先日はここで終わった。この”X-Powered-By: PHP/7.0.14“も消したい。調べてみると、httpd側の設定ではなくPHP側の設定のようである。

■ /etc/php.ini

設定ファイルを編集する。

$ sudo vi /etc/php.ini

設定内容は下記の通りである。

expose_php = Off

デフォルトでは”On“になっていたので”Off“にする。これで再度アクセスしてみると下記のようになった。

$ curl -I https://www.example.com/
HTTP/1.1 200 OK
Date: Thu, 09 Feb 2017 10:22:19 GMT
Server: Apache
  :

満足である。

以上。

■ 関連