XserverVPSでWordPress環境を構築していきます。Xserverでは無くとも、Ubuntuならば同様にできるようになっています。
2回目は、Webに強いプログラミング言語のPHPのインストールについてです。
PHP8.3のインストール
PHP(PHP: Hypertext Preprocessor)は、主にウェブ開発で使用されるサーバーサイドのスクリプト言語です。
WordPressを構築するには必要な言語となります。
2024/6時点ではVer.8.3が最新ですので、こちらをインストールしていきます。
# apt -y install php8.3 php8.3-mbstring php-pear php8.3-mysql
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libapache2-mod-php8.3 php-common php-xml php8.3-cli php8.3-common
php8.3-opcache php8.3-readline php8.3-xml
The following NEW packages will be installed:
libapache2-mod-php8.3 php-common php-pear php-xml php8.3 php8.3-cli
php8.3-common php8.3-mbstring php8.3-mysql php8.3-opcache php8.3-readline
php8.3-xml
0 upgraded, 12 newly installed, 0 to remove and 70 not upgraded.
Need to get 5968 kB of archives.
After this operation, 26.7 MB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php-common all 2:93ubuntu2 [13.9 kB]
Get:2 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-common amd64 8.3.6-0maysync1 [738 kB]
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-opcache amd64 8.3.6-0maysync1 [371 kB]
Get:4 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-readline amd64 8.3.6-0maysync1 [13.5 kB]
Get:5 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-cli amd64 8.3.6-0maysync1 [1915 kB]
Get:6 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libapache2-mod-php8.3 amd64 8.3.6-0maysync1 [1849 kB]
Get:7 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-xml amd64 8.3.6-0maysync1 [126 kB]
Get:8 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php-xml all 2:8.3+93ubuntu2 [1856 B]
Get:9 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php-pear all 1:1.10.13+submodules+notgz+2022032202-2build1 [292 kB]
Get:10 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3 all 8.3.6-0maysync1 [9166 B]
Get:11 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-mbstring amd64 8.3.6-0maysync1 [512 kB]
Get:12 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-mysql amd64 8.3.6-0maysync1 [126 kB]
Fetched 5968 kB in 2s (2826 kB/s)
Selecting previously unselected package php-common.
(Reading database ... 67514 files and directories currently installed.)
Preparing to unpack .../00-php-common_2%3a93ubuntu2_all.deb ...
Unpacking php-common (2:93ubuntu2) ...
Selecting previously unselected package php8.3-common.
Preparing to unpack .../01-php8.3-common_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-common (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-opcache.
Preparing to unpack .../02-php8.3-opcache_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-opcache (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-readline.
Preparing to unpack .../03-php8.3-readline_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-readline (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-cli.
Preparing to unpack .../04-php8.3-cli_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-cli (8.3.6-0maysync1) ...
Selecting previously unselected package libapache2-mod-php8.3.
Preparing to unpack .../05-libapache2-mod-php8.3_8.3.6-0maysync1_amd64.deb ...
Unpacking libapache2-mod-php8.3 (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-xml.
Preparing to unpack .../06-php8.3-xml_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-xml (8.3.6-0maysync1) ...
Selecting previously unselected package php-xml.
Preparing to unpack .../07-php-xml_2%3a8.3+93ubuntu2_all.deb ...
Unpacking php-xml (2:8.3+93ubuntu2) ...
Selecting previously unselected package php-pear.
Preparing to unpack .../08-php-pear_1%3a1.10.13+submodules+notgz+2022032202-2build1_all.deb ...
Unpacking php-pear (1:1.10.13+submodules+notgz+2022032202-2build1) ...
Selecting previously unselected package php8.3.
Preparing to unpack .../09-php8.3_8.3.6-0maysync1_all.deb ...
Unpacking php8.3 (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-mbstring.
Preparing to unpack .../10-php8.3-mbstring_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-mbstring (8.3.6-0maysync1) ...
Selecting previously unselected package php8.3-mysql.
Preparing to unpack .../11-php8.3-mysql_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-mysql (8.3.6-0maysync1) ...
Setting up php-common (2:93ubuntu2) ...
Created symlink /etc/systemd/system/timers.target.wants/phpsessionclean.timer → /usr/lib/systemd/system/phpsessionclean.timer.
Setting up php8.3-common (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/calendar.ini with new version
Creating config file /etc/php/8.3/mods-available/ctype.ini with new version
Creating config file /etc/php/8.3/mods-available/exif.ini with new version
Creating config file /etc/php/8.3/mods-available/fileinfo.ini with new version
Creating config file /etc/php/8.3/mods-available/ffi.ini with new version
Creating config file /etc/php/8.3/mods-available/ftp.ini with new version
Creating config file /etc/php/8.3/mods-available/gettext.ini with new version
Creating config file /etc/php/8.3/mods-available/iconv.ini with new version
Creating config file /etc/php/8.3/mods-available/pdo.ini with new version
Creating config file /etc/php/8.3/mods-available/phar.ini with new version
Creating config file /etc/php/8.3/mods-available/posix.ini with new version
Creating config file /etc/php/8.3/mods-available/shmop.ini with new version
Creating config file /etc/php/8.3/mods-available/sockets.ini with new version
Creating config file /etc/php/8.3/mods-available/sysvmsg.ini with new version
Creating config file /etc/php/8.3/mods-available/sysvsem.ini with new version
Creating config file /etc/php/8.3/mods-available/sysvshm.ini with new version
Creating config file /etc/php/8.3/mods-available/tokenizer.ini with new version
Setting up php8.3-mysql (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/mysqlnd.ini with new version
Creating config file /etc/php/8.3/mods-available/mysqli.ini with new version
Creating config file /etc/php/8.3/mods-available/pdo_mysql.ini with new version
Setting up php8.3-mbstring (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/mbstring.ini with new version
Setting up php8.3-readline (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/readline.ini with new version
Setting up php8.3-xml (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/dom.ini with new version
Creating config file /etc/php/8.3/mods-available/simplexml.ini with new version
Creating config file /etc/php/8.3/mods-available/xml.ini with new version
Creating config file /etc/php/8.3/mods-available/xmlreader.ini with new version
Creating config file /etc/php/8.3/mods-available/xmlwriter.ini with new version
Creating config file /etc/php/8.3/mods-available/xsl.ini with new version
Setting up php8.3-opcache (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/opcache.ini with new version
Setting up php-xml (2:8.3+93ubuntu2) ...
Setting up php8.3-cli (8.3.6-0maysync1) ...
update-alternatives: using /usr/bin/php8.3 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar8.3 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar8.3 to provide /usr/bin/phar.phar (phar.phar) in auto mode
Creating config file /etc/php/8.3/cli/php.ini with new version
Setting up libapache2-mod-php8.3 (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php8.3
Setting up php-pear (1:1.10.13+submodules+notgz+2022032202-2build1) ...
Setting up php8.3 (8.3.6-0maysync1) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for php8.3-cli (8.3.6-0maysync1) ...
Processing triggers for libapache2-mod-php8.3 (8.3.6-0maysync1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
画像を生成および操作するためのライブラリであるGDも必要ですので、追加でインストールします。
# apt install php8.3-gd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
fontconfig-config fonts-dejavu-core fonts-dejavu-mono libaom3 libde265-0
libdeflate0 libfontconfig1 libgd3 libheif-plugin-aomdec
libheif-plugin-aomenc libheif-plugin-libde265 libheif1 libjbig0
libjpeg-turbo8 libjpeg8 liblerc4 libsharpyuv0 libtiff6 libwebp7 libxpm4
Suggested packages:
libgd-tools libheif-plugin-x265 libheif-plugin-ffmpegdec
libheif-plugin-jpegdec libheif-plugin-jpegenc libheif-plugin-j2kdec
libheif-plugin-j2kenc libheif-plugin-rav1e libheif-plugin-svtenc
The following NEW packages will be installed:
fontconfig-config fonts-dejavu-core fonts-dejavu-mono libaom3 libde265-0
libdeflate0 libfontconfig1 libgd3 libheif-plugin-aomdec
libheif-plugin-aomenc libheif-plugin-libde265 libheif1 libjbig0
libjpeg-turbo8 libjpeg8 liblerc4 libsharpyuv0 libtiff6 libwebp7 libxpm4
php8.3-gd
0 upgraded, 21 newly installed, 0 to remove and 70 not upgraded.
Need to get 4974 kB of archives.
After this operation, 14.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 fonts-dejavu-mono all 2.37-8 [502 kB]
Get:2 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 fonts-dejavu-core all 2.37-8 [835 kB]
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 fontconfig-config amd64 2.15.0-1.1ubuntu2 [37.3 kB]
Get:4 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 libaom3 amd64 3.8.2-2ubuntu0.1 [1941 kB]
Get:5 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libde265-0 amd64 1.0.15-1build3 [166 kB]
Get:6 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libdeflate0 amd64 1.19-1build1 [43.8 kB]
Get:7 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libfontconfig1 amd64 2.15.0-1.1ubuntu2 [139 kB]
Get:8 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libsharpyuv0 amd64 1.3.2-0.4build3 [15.8 kB]
Get:9 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libheif-plugin-aomdec amd64 1.17.6-1ubuntu4 [10.3 kB]
Get:10 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libheif-plugin-libde265 amd64 1.17.6-1ubuntu4 [8158 B]
Get:11 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libheif1 amd64 1.17.6-1ubuntu4 [276 kB]
Get:12 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libjpeg-turbo8 amd64 2.1.5-2ubuntu2 [150 kB]
Get:13 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libjpeg8 amd64 8c-2ubuntu11 [2148 B]
Get:14 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libjbig0 amd64 2.1-6.1ubuntu2 [29.7 kB]
Get:15 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 liblerc4 amd64 4.0.0+ds-4ubuntu2 [179 kB]
Get:16 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libwebp7 amd64 1.3.2-0.4build3 [230 kB]
Get:17 http://nova.clouds.archive.ubuntu.com/ubuntu noble-updates/main amd64 libtiff6 amd64 4.5.1+git230720-4ubuntu2.1 [199 kB]
Get:18 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libxpm4 amd64 1:3.5.17-1build2 [36.5 kB]
Get:19 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libgd3 amd64 2.3.3-9ubuntu5 [128 kB]
Get:20 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 libheif-plugin-aomenc amd64 1.17.6-1ubuntu4 [14.7 kB]
Get:21 http://nova.clouds.archive.ubuntu.com/ubuntu noble/main amd64 php8.3-gd amd64 8.3.6-0maysync1 [31.2 kB]
Fetched 4974 kB in 3s (1535 kB/s)
Selecting previously unselected package fonts-dejavu-mono.
(Reading database ... 69879 files and directories currently installed.)
Preparing to unpack .../00-fonts-dejavu-mono_2.37-8_all.deb ...
Unpacking fonts-dejavu-mono (2.37-8) ...
Selecting previously unselected package fonts-dejavu-core.
Preparing to unpack .../01-fonts-dejavu-core_2.37-8_all.deb ...
Unpacking fonts-dejavu-core (2.37-8) ...
Selecting previously unselected package fontconfig-config.
Preparing to unpack .../02-fontconfig-config_2.15.0-1.1ubuntu2_amd64.deb ...
Unpacking fontconfig-config (2.15.0-1.1ubuntu2) ...
Selecting previously unselected package libaom3:amd64.
Preparing to unpack .../03-libaom3_3.8.2-2ubuntu0.1_amd64.deb ...
Unpacking libaom3:amd64 (3.8.2-2ubuntu0.1) ...
Selecting previously unselected package libde265-0:amd64.
Preparing to unpack .../04-libde265-0_1.0.15-1build3_amd64.deb ...
Unpacking libde265-0:amd64 (1.0.15-1build3) ...
Selecting previously unselected package libdeflate0:amd64.
Preparing to unpack .../05-libdeflate0_1.19-1build1_amd64.deb ...
Unpacking libdeflate0:amd64 (1.19-1build1) ...
Selecting previously unselected package libfontconfig1:amd64.
Preparing to unpack .../06-libfontconfig1_2.15.0-1.1ubuntu2_amd64.deb ...
Unpacking libfontconfig1:amd64 (2.15.0-1.1ubuntu2) ...
Selecting previously unselected package libsharpyuv0:amd64.
Preparing to unpack .../07-libsharpyuv0_1.3.2-0.4build3_amd64.deb ...
Unpacking libsharpyuv0:amd64 (1.3.2-0.4build3) ...
Selecting previously unselected package libheif-plugin-aomdec:amd64.
Preparing to unpack .../08-libheif-plugin-aomdec_1.17.6-1ubuntu4_amd64.deb ...
Unpacking libheif-plugin-aomdec:amd64 (1.17.6-1ubuntu4) ...
Selecting previously unselected package libheif-plugin-libde265:amd64.
Preparing to unpack .../09-libheif-plugin-libde265_1.17.6-1ubuntu4_amd64.deb ...
Unpacking libheif-plugin-libde265:amd64 (1.17.6-1ubuntu4) ...
Selecting previously unselected package libheif1:amd64.
Preparing to unpack .../10-libheif1_1.17.6-1ubuntu4_amd64.deb ...
Unpacking libheif1:amd64 (1.17.6-1ubuntu4) ...
Selecting previously unselected package libjpeg-turbo8:amd64.
Preparing to unpack .../11-libjpeg-turbo8_2.1.5-2ubuntu2_amd64.deb ...
Unpacking libjpeg-turbo8:amd64 (2.1.5-2ubuntu2) ...
Selecting previously unselected package libjpeg8:amd64.
Preparing to unpack .../12-libjpeg8_8c-2ubuntu11_amd64.deb ...
Unpacking libjpeg8:amd64 (8c-2ubuntu11) ...
Selecting previously unselected package libjbig0:amd64.
Preparing to unpack .../13-libjbig0_2.1-6.1ubuntu2_amd64.deb ...
Unpacking libjbig0:amd64 (2.1-6.1ubuntu2) ...
Selecting previously unselected package liblerc4:amd64.
Preparing to unpack .../14-liblerc4_4.0.0+ds-4ubuntu2_amd64.deb ...
Unpacking liblerc4:amd64 (4.0.0+ds-4ubuntu2) ...
Selecting previously unselected package libwebp7:amd64.
Preparing to unpack .../15-libwebp7_1.3.2-0.4build3_amd64.deb ...
Unpacking libwebp7:amd64 (1.3.2-0.4build3) ...
Selecting previously unselected package libtiff6:amd64.
Preparing to unpack .../16-libtiff6_4.5.1+git230720-4ubuntu2.1_amd64.deb ...
Unpacking libtiff6:amd64 (4.5.1+git230720-4ubuntu2.1) ...
Selecting previously unselected package libxpm4:amd64.
Preparing to unpack .../17-libxpm4_1%3a3.5.17-1build2_amd64.deb ...
Unpacking libxpm4:amd64 (1:3.5.17-1build2) ...
Selecting previously unselected package libgd3:amd64.
Preparing to unpack .../18-libgd3_2.3.3-9ubuntu5_amd64.deb ...
Unpacking libgd3:amd64 (2.3.3-9ubuntu5) ...
Selecting previously unselected package libheif-plugin-aomenc:amd64.
Preparing to unpack .../19-libheif-plugin-aomenc_1.17.6-1ubuntu4_amd64.deb ...
Unpacking libheif-plugin-aomenc:amd64 (1.17.6-1ubuntu4) ...
Selecting previously unselected package php8.3-gd.
Preparing to unpack .../20-php8.3-gd_8.3.6-0maysync1_amd64.deb ...
Unpacking php8.3-gd (8.3.6-0maysync1) ...
Setting up libsharpyuv0:amd64 (1.3.2-0.4build3) ...
Setting up libaom3:amd64 (3.8.2-2ubuntu0.1) ...
Setting up liblerc4:amd64 (4.0.0+ds-4ubuntu2) ...
Setting up libxpm4:amd64 (1:3.5.17-1build2) ...
Setting up libdeflate0:amd64 (1.19-1build1) ...
Setting up libjbig0:amd64 (2.1-6.1ubuntu2) ...
Setting up fonts-dejavu-mono (2.37-8) ...
Setting up fonts-dejavu-core (2.37-8) ...
Setting up libjpeg-turbo8:amd64 (2.1.5-2ubuntu2) ...
Setting up libwebp7:amd64 (1.3.2-0.4build3) ...
Setting up libde265-0:amd64 (1.0.15-1build3) ...
Setting up libjpeg8:amd64 (8c-2ubuntu11) ...
Setting up fontconfig-config (2.15.0-1.1ubuntu2) ...
Setting up libtiff6:amd64 (4.5.1+git230720-4ubuntu2.1) ...
Setting up libheif-plugin-aomdec:amd64 (1.17.6-1ubuntu4) ...
Setting up libheif1:amd64 (1.17.6-1ubuntu4) ...
Setting up libheif-plugin-libde265:amd64 (1.17.6-1ubuntu4) ...
Setting up libheif-plugin-aomenc:amd64 (1.17.6-1ubuntu4) ...
Processing triggers for libc-bin (2.39-0ubuntu8) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libapache2-mod-php8.3 (8.3.6-0maysync1) ...
Processing triggers for sgml-base (1.31) ...
Setting up libfontconfig1:amd64 (2.15.0-1.1ubuntu2) ...
Setting up libgd3:amd64 (2.3.3-9ubuntu5) ...
Setting up php8.3-gd (8.3.6-0maysync1) ...
Creating config file /etc/php/8.3/mods-available/gd.ini with new version
Processing triggers for libc-bin (2.39-0ubuntu8) ...
Processing triggers for libapache2-mod-php8.3 (8.3.6-0maysync1) ...
Processing triggers for php8.3-cli (8.3.6-0maysync1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
バージョン確認
# php -v
PHP 8.3.6 (cli) (built: Apr 15 2024 19:21:47) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
設定ファイルの修正
php.ini(設定ファイル)の場所
CLI(コマンドラインインターフェース)用のphp.ini
/etc/php/[PHPバージョン]/cli/php.ini
にあります。今回の場合
/etc/php/8.3/cli/php.ini
になります。
コマンドラインで操作しない場合、こちらは変更する必要はありません。
勿論、変更しても大丈夫です。
Apache用のphp.ini
/etc/php/[PHPバージョン]/apache2/php.ini
にあります。今回の場合
/etc/php/8.3/apache2/php.ini
になります。
WordPressなどでWebサーバーとして動かす場合、こちらの修正は必須になります。
php.iniの修正
修正する内容は、以下7点です。
viエディタで修正していきます。(他のエディタでも構いません)
# vi /etc/php/8.3/apache2/php.ini
viエディタ内のコマンドで/を押すと検索モードになります。
/検索キーワード[エンターキー]
で該当部位に飛びます。(キーイン中から該当箇所が絞られていきます。エンターで検索終了です。)
iキーでinsertモードになり、修正することが可能です。
phpのversion非表示
/expose_phpで検索します。
expose_php = OnをOff
バージョンによる脆弱性を突いた攻撃をされないように、バージョンを非表示にします。
該当箇所は以下のようになります。
;;;;;;;;;;;;;;;;;
; Miscellaneous ;
;;;;;;;;;;;;;;;;;
; 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.
; https://php.net/expose-php
expose_php = Off
POSTサイズの変更
/post_max_sizeで検索します。
post_max_size = 8M を20M
POST通信のときの最大サイズです。
該当箇所は以下のようになります。
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 20M
UPLOADサイズの変更
/upload_maxで検索します。
upload_max_filesize = 2Mを20M
アップロードのファイルサイズです。初期値の2Mは小さいので、WordPressのテーマをアップロードする際に困ることになります。
該当箇所は以下のようになります。
; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
upload_max_filesize = 20M
タイムゾーンの設定
/timezoneで検索します。
;date.timezone =
先頭のコメントアウト;を外し、東京時間を設定します。
date.timezone = “Asia/Tokyo”
該当箇所は以下のようになります。
[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = "Asia/Tokyo"
マルチバイト対応
/mbstringで検索します。
;mbstring.language = Japanese
先頭のコメントアウト;を削除し日本語を有効化します。
mbstirng.language = Japanese
該当箇所は以下のようになります。
[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; https://php.net/mbstring.language
mbstring.language = Japanese
文字エンコーディングをUTF-8に設定
そのまま下に移ります。
;mbstring.internal_encoding =
コメントアウトを外し、UTF-8を指定します。
mbstring.internal_encoding = UTF-8
HPPTでの文字コードをUTFに設定
;mbstring.http_input =
コメントアウトを外し、UTF-8を指定します。
mbstring.http_input = UTF-8
該当箇所は以下のようになります。
; Use of this INI entry is deprecated, use global internal_encoding instead.
; internal/script encoding.
; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
mbstring.internal_encoding = UTF-8
; Use of this INI entry is deprecated, use global input_encoding instead.
; http input encoding.
; mbstring.encoding_translation = On is needed to use this setting.
; If empty, default_charset or input_encoding or mbstring.input is used.
; The precedence is: default_charset < input_encoding < mbstring.http_input
; https://php.net/mbstring.http-input
mbstring.http_input = UTF-8
viエディターの保存終了は:wqです。ESCキーを押してInsertモードを解除し、:を押すとコマンドが入力できるので、wqと入れてエンターを押します。
修正の反映
Apache2を再起動して、設定を反映させます。
# systemctl restart apache2
設定の確認
phpinfo()関数による設定出力
phpinfo()を使うことで、設定を表形式に出力することができます。
この関数を使うだけのページを作成します。
セキュリティー上、一時的な作成にして、後で削除しておいてください。
# vi /var/www/html/info.php
phpファイルの中身は、1行だけの簡単なものです。
<?php phpinfo(); ?>
ブラウザから
ドメイン名/info.php
でページを呼び出してみてください。
下記の様に表示されれば成功です。
先ほど設定変更した、タイムゾーンやマルチバイト、エンコーディングなどが反映されているか確認してみてください。
info.phpファイルの削除
無事表示されたら、セキュリティーの観点からinfo.phpを消しておきます。
必要なら、このページをローカルに保存して確認できるようにしておいても良いと思います。
# rm /var/www/html/info.php
以上でPHPのインストールは終わりです。
ご覧いただき有難うございました。良かったら いいね(thumb up)ボタンをお願いします。
PR
コメント