end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install php ver.7.3.15 and wordpress ver.5.3.2

次のurlにあるentryの 2017 -> 2020年版です。

phpの2020/3 での最新は ver.7.4.3 ですが、 ver.7.4より別moduleになった Oniguruma(正規表現ライブラリ)のinstall後、 ver.7.4を上手くinstallできなかった為、php ver.7.3.15 を使用しています。

php が依存するlibrary の install

re2c - lexer generator for C/C++

$ wget https://github.com/skvadrik/re2c/archive/1.3.tar.gz
$ tar -xvf 1.3.tar.gz
$ cd re2c-1.3
$ autoreconf -i -W all
$ ./configure
$ make
$ make check
$ sudo make install

re2c が依存するlibraryは、 https://re2c.org/install/install.html に 記載されています。 これによれば、buildは C++ compiler のみ必要とするようですが、 私の場合、「autoreconf -i -W all」実行時に次のようなerrorとなった為、 libtool を installしています。

$ autoreconf -i -W all
aclocal: warning: couldn't open directory 'm4': No such file or directory
Makefile.am:385: error: Libtool library used but 'LIBTOOL' is undefined
Makefile.am:385:   The usual way to define 'LIBTOOL' is to add 'LT_INIT'
Makefile.am:385:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
Makefile.am:385:   If 'LT_INIT' is in 'configure.ac', make sure
Makefile.am:385:   its definition is in aclocal's search path.
autoreconf: automake failed with exit status: 1

$ sudo yum install libtool

flex - lexical analyser

$ wget https://github.com/westes/flex/files/981163/flex-2.6.4.tar.gz
$ tar -xvf flex-2.6.4.tar.gz
$ cd flex-2.6.4
$ ./configure
$ make
$ make check
$ sudo make install

bison - general-purpose parser generator

https://www.gnu.org/software/bison/

$ wget http://ftp.gnu.org/gnu/bison/bison-3.5.3.tar.gz
$ tar -zxvf bison-3.5.3.tar.gz
$ cd bison-3.5.3
$ ./configure
$ make
$ make check
$ sudo make install

libxml2-devel

make check で threadsのerrorが発生しましたが、無視して先に勧めています

$ wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.9.tar.gz
$ tar -xvf libxml2-sources-2.9.9.tar.gz
$ cd libxml2-sources-2.9.9
$ ./configure
$ make
$ make check
 :
## C14N 1.1 without comments regression tests
## Catalog and Threads regression tests
I/O warning : failed to load external entity "test/threads/invalid.xml"
parse failed
I/O error : failed to load external entity "test/threads/bca.xml"
parse failed
I/O error : failed to load external entity "test/threads/abc.xml"
parse failed
I/O error : failed to load external entity "test/threads/acb.xml"
parse failed
I/O error : failed to load external entity "test/threads/bac.xml"
parse failed
I/O error : failed to load external entity "test/threads/cba.xml"
parse failed
I/O error : failed to load external entity "test/threads/cab.xml"
parse failed
Thread 0 handling test/threads/abc.xml failed
Thread 1 handling test/threads/acb.xml failed
Thread 2 handling test/threads/bac.xml failed
Thread 3 handling test/threads/bca.xml failed
Thread 4 handling test/threads/cab.xml failed
Thread 5 handling test/threads/cba.xml failed
Thread 6 handling test/threads/invalid.xml failed
I/O error : failed to load external entity "test/threads/bca.xml"
parse failed
I/O error : failed to load external entity "test/threads/cab.xml"
parse failed
I/O error : failed to load external entity "test/threads/abc.xml"
parse failed
I/O error : failed to load external entity "test/threads/acb.xml"
parse failed
I/O error : failed to load external entity "test/threads/cba.xml"
parse failed
I/O warning : failed to load external entity "test/threads/invalid.xml"
parse failed
I/O error : failed to load external entity "test/threads/bac.xml"
parse failed
 :
sudo make install 

ICU - International Components for Unicode

$ wget https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.tgz
$ cd icu/source
$ make
$ make check
$ sudo make install

php 本体

$ wget https://www.php.net/distributions/php-7.4.3.tar.gz
$ ./configure \
  --with-apxs2=/home/end0tknr/local/apache/bin/apxs \
  --enable-mbstring \
  --with-mysqli=/usr/local/mysql/bin/mysql_config \
  --with-pdo-mysql=/usr/local/mysql/bin/mysql_config \
  --with-openssl=/usr/local/openssl_1_1_1 \
  --with-zlib=/usr
  :
checking for mysql_set_server_option in -lmysqlclient_r... no
configure: error: wrong mysql library version or lib not found.
Check config.log for more information.

今回、centos8やmysql8 を利用した影響でしょうか、 configureにて上記のようなerrorとなった為、 次のurlを参考に「mysqlnd」に変更しています。

https://stackoverflow.com/questions/54625966/error-wrong-mysql-library-version-or-lib-not-found-when-building-php-7-with-a

$ ./configure \
  --with-apxs2=/home/end0tknr/local/apache/bin/apxs \
  --enable-mbstring \
  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-openssl=/usr/local/openssl_1_1_1 \
  --with-zlib=/usr
$ make
$ make test
$ sudo make install

$ sudo cp php.ini-development php.ini-production /etc/
$ sudo ln -s /etc/php.ini-production /etc/php.ini

wordpress

mysql8に対し、create database & create user

refer to https://qiita.com/ucan-lab/items/3ae911b7e13287a5b917

$ /usr/local/mysql/bin/mysql -u root -p

mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8;

mysql> CREATE USER 'wordpress'
         IDENTIFIED WITH mysql_native_password
     BY 'ないしょ';
mysql> GRANT ALL ON wordpress.* TO 'ないしょ';

mysql>  SELECT user, host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| wordpress        | %         | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+

mysql8より defaultの認証方式が caching_sha2_password になっており、 そのままでは、wordpress からの db接続に失敗する為、 上記では「WITH mysql_native_password」を追加しています。

参考までに wordpress からの db接続失敗時のerrorは以下の通りです。

PHP Warning:  mysqli_real_connect():
  The server requested authentication method unknown to the client
  [caching_sha2_password]
  in /home/end0tknr/dev/Test/wordpress/wp-includes/wp-db.php on line 1633
PHP Warning:  mysqli_real_connect():
  (HY000/2054): The server requested authentication method unknown
  to the client
  in /home/end0tknr/dev/Test/wordpress/wp-includes/wp-db.php on line 1633

apache httpd.conf 変更

$ vi /home/end0tknr/local/apache/conf/httpd.conf

#以下を追加

<Directory "/home/end0tknr/dev/Test">
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>
Alias /Test /home/end0tknr/dev/Test

wordpressのdownloadと設定

$ pwd
/home/end0tknr/dev/Test
$ wget https://ja.wordpress.org/wordpress-5.3.2-ja.tar.gz
$ tar -xvf wordpress-5.3.2-ja.tar.gz
$ cd wordpress
$ cp wp-config-sample.php wp-config.php

$ vi wp-config.php

define( 'DB_NAME',    'wordpress' );
define( 'DB_USER',    'ないしょ' );
define( 'DB_PASSWORD','wordpress' );
define( 'DB_HOST',    'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', '/home/end0tknr/local/apache/logs/wp_errors.log' );

wordpressのinstall

後は、ブラウザから wordpress/wp-admin/install.phpaccessすれば、OKです。