TestLink を MariaDB で導入

#前回からの経緯

https://qiita.com/ifor2u/items/2ebe1544e1d9b4867e03

前回、TestLinkをpostgresqlで導入をお試みたがうまくいかなかったので、今後はMariaDBに置き換えて引き続きTestLinkの導入を試みる。
# MariaDBをインストール
```bash
sudo dnf install -y name=mariadb-server
sudo dnf install -y name=php81-php-mysqlnd
```

# MariaDB を初期化
```bash
$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] 
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
$ sudo systemctl start mariadb
```
# またエラー
画面上は、エラーと表示されていないが、中途半端な出力に見える。
![スクリーンショット 2023-10-23 21.10.13.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/e7b88005-93e3-b5cc-5eed-68c65d821f40.png)

```
# /var/opt/remi/php81/log/php-fpm/www-error.log
[22-Oct-2023 20:19:07 UTC] PHP Fatal error:  Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /var/www/html/testlink/install/installNewDB.php:636
Stack trace:
#0 /var/www/html/testlink/install/installNewDB.php(636): fwrite()
#1 /var/www/html/testlink/install/installNewDB.php(534): write_config_db()
#2 {main}
  thrown in /var/www/html/testlink/install/installNewDB.php on line 636
```
installNewDB.phpの636行目を元にソースコードを見てみる。
../config_db.inc.phpの書き込みができずにエラーになったのでは無いかと推測。installNewDB.phpの1つ上のディレクトリ階層に書き込みできるように設定指定みる。
```php
    533 $cfg_file = "../config_db.inc.php";
    534 $yy = write_config_db($cfg_file,$data);
〜省略〜
    598 function write_config_db($filename, $data)
    599 {
    600   $ret = array('status'     => 'ok', 'cfg_string' => '');
〜省略〜
    630   if (@!$handle = fopen($filename, 'w'))
    631   {
    632     $ret['status'] = 'ko';
    633   }
    634 
    635   // Write $somecontent to our opened file.
    636   if (@fwrite($handle, $configString) === FALSE)
    637   {
    638     $ret['status'] = 'ko';
    639   }
```

# selinuxの設定を行う
```
$ sudo /usr/sbin/semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/testlink
$ sudo /usr/sbin/restorecon -R /var/www/html/testlink
```
# 今度はうまく行ったようだ
![スクリーンショット 2023-10-23 21.18.27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/0ef2b023-9c02-8f5c-ecd6-8c546d1a18fa.png)
![スクリーンショット 2023-10-23 21.18.38.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/4f94744c-2d1a-5fec-1175-40256a99e308.png)

# トップページへアクセス
http://localhost/testlink
それっぽい画面が表示されるようになった。
![スクリーンショット 2023-10-23 21.20.43.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/baee07aa-3346-8215-45fb-bf1da3460e17.png)
![スクリーンショット 2023-10-23 21.21.36.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/3788d9f4-9b5e-f5f7-6494-ea80eb6abbaa.png)
![スクリーンショット 2023-10-23 21.22.26.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/50452/1ecdf27d-ef10-ec3e-c67b-a0a74a1fc05e.png)

# 導入できた環境
- CentOS Stream 9(5.14.0-319.el9.x86_64)
- mariadb 10.5.16
- php 8.1
- testlink 2.0.0-20220827-PHP8.1