nginxでTestLinkを動かしてみる
先日、DockerでTestLinkのsamba-ad連携してみたけど。dockerを動かすには貧弱なAzureのVMを使用しているのでnginxでバーチャルホスト切って動かしてみることにしました。
これもまた先人のお知恵を拝借してと思いましたが、Dockerで作成されているものが多数で結構、情報が少ないのかなと思ってひとまずまとめておくことにしてみました。需要あるかわかりませんが、少なくとも自分はこういう構成でやるのでまとめてくれるのがなくて困った。というよりこういうのはDockerでやれという話ですね。
◆対象Version
Ubuntu20.04.3LTS
◆手順
1.PHPインストール
$ sudo apt -y install php7.4 $ sudo apt -y install php-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip
2.データベースや添付ファイル保管用ディレクトリマウント
*先にAzureファイル共有のストレージアカウントを準備しておく
# 環境変数設定
$ export AZUREFILES_RGN="VirtualMachineExamination"
$ export AZUREFILES_SA="testlink"
$ export AZUREFILES_TESTLINK_DB_FSN="testlink-database"
$ export AZUREFILES_TESTLINK_DB_MNT="/mnt/$AZUREFILES_SA/$AZUREFILES_TESTLINK_DB_FSN"
$ export AZUREFILES_TESTLINK_FILE_FSN="testlink-file"
$ export AZUREFILES_TESTLINK_FILE_MNT="/mnt/$AZUREFILES_SA/$AZUREFILES_TESTLINK_FILE_FSN"
$ vi azurefilesmount_testlink_database.sh
#ファイルを作成
---------------------------
#! /bin/bash
resourceGroupName=$AZUREFILES_RGN
storageAccountName=$AZUREFILES_SA
fileShareName=$AZUREFILES_TESTLINK_DB_FSN
mntPath="/mnt/$storageAccountName/$fileShareName"
sudo mkdir -p $mntPath
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir "/etc/smbcredentials"
fi
storageAccountKey=$(az storage account keys list \
--resource-group $resourceGroupName \
--account-name $storageAccountName \
--query "[0].value" | tr -d '"')
smbCredentialFile="/etc/smbcredentials/$storageAccountName.cred"
if [ ! -f $smbCredentialFile ]; then
echo "username=$storageAccountName" | sudo tee $smbCredentialFile > /dev/null
echo "password=$storageAccountKey" | sudo tee -a $smbCredentialFile > /dev/null
else
echo "The credential file $smbCredentialFile already exists, and was not modified."
fi
sudo chmod 600 $smbCredentialFile
# This command assumes you have logged in with az login
httpEndpoint=$(az storage account show \
--resource-group $resourceGroupName \
--name $storageAccountName \
--query "primaryEndpoints.file" | tr -d '"')
smbPath=$(echo $httpEndpoint | cut -c7-$(expr length $httpEndpoint))$fileShareName
if [ -z "$(grep $mntPath /etc/fstab)" ]; then
echo "$smbPath $mntPath cifs nofail,vers=3.0,file_mode=0750,dir_mode=0700,uid=118,gid=128,credentials=$smbCredentialFile,serverino" | sudo tee -a /etc/fstab > /dev/null
else
echo "/etc/fstab was not modified to avoid conflicting entries as this Azure file share was already present. You may want to double check /etc/fstab to ensure the configuration is as desired."
fi
---------------------------
$ chmod a+x azurefilesmount_testlink_database.sh
$ ./azurefilesmount_testlink_database.sh
$ vi azurefilesmount_testlink_file.sh
#ファイルを作成
---------------------------
#! /bin/bash
resourceGroupName=$AZUREFILES_RGN
storageAccountName=$AZUREFILES_SA
fileShareName=$AZUREFILES_TESTLINK_FILE_FSN
mntPath="/mnt/$storageAccountName/$fileShareName"
sudo mkdir -p $mntPath
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir "/etc/smbcredentials"
fi
storageAccountKey=$(az storage account keys list \
--resource-group $resourceGroupName \
--account-name $storageAccountName \
--query "[0].value" | tr -d '"')
smbCredentialFile="/etc/smbcredentials/$storageAccountName.cred"
if [ ! -f $smbCredentialFile ]; then
echo "username=$storageAccountName" | sudo tee $smbCredentialFile > /dev/null
echo "password=$storageAccountKey" | sudo tee -a $smbCredentialFile > /dev/null
else
echo "The credential file $smbCredentialFile already exists, and was not modified."
fi
sudo chmod 600 $smbCredentialFile
# This command assumes you have logged in with az login
httpEndpoint=$(az storage account show \
--resource-group $resourceGroupName \
--name $storageAccountName \
--query "primaryEndpoints.file" | tr -d '"')
smbPath=$(echo $httpEndpoint | cut -c7-$(expr length $httpEndpoint))$fileShareName
if [ -z "$(grep $mntPath /etc/fstab)" ]; then
echo "$smbPath $mntPath cifs nofail,vers=3.0,file_mode=0750,dir_mode=0777,uid=33,gid=33,credentials=$smbCredentialFile,serverino" | sudo tee -a /etc/fstab > /dev/null
else
echo "/etc/fstab was not modified to avoid conflicting entries as this Azure file share was already present. You may want to double check /etc/fstab to ensure the configuration is as desired."
fi
---------------------------
$ chmod a+x azurefilesmount_testlink_file.sh
$ ./azurefilesmount_testlink_file.sh
$ sudo mount -a
$ df -h
3.MariaDBインストール
$ sudo apt-get install mariadb-server mariadb-client
$ mysql --version
mysql Ver 15.1 Distrib 10.3.32-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
#移動先ディレクトリ確認
$ sudo ls -al /mnt/testlink/
#データベースファイルコピー
$ sudo systemctl stop mariadb.service
$ cd /var/lib/mysql
$ sudo cp -Rp * /mnt/testlink/testlink-database/
#元ディレクトリ退避
$ sudo mv /var/lib/mysql /var/lib/mysql.old
$ sudo ln -s /mnt/testlink/testlink-database /var/lib/mysql
$ sudo ls
$ sudo systemctl start mariadb
$ sudo systemctl status mariadb
$ sudo rm -rf /var/lib/mysql.old
#MariaDB設定
$ sudo /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
~中略~
Enter current password for root (enter for none): #Enter押下
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password: yourpassword
Re-enter new password: yourpassword
Password updated successfully!
Reloading privilege tables..
... Success!
~中略~
Remove anonymous users? [Y/n] Y
... Success!
~中略~
Disallow root login remotely? [Y/n] Y
... Success!
~中略~
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
~中略~
eload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
~中略~
Thanks for using MariaDB!
#TestLinkデータベース作成
$ sudo mysql -u root -p
Enter password:yourpassword
~中略~
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION ;
MariaDB [(none)]> CREATE DATABASE testlink;
MariaDB [(none)]> CREATE USER 'testlink'@'localhost' IDENTIFIED BY 'yourpassword';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON testlink.* TO 'testlink'@'localhost' IDENTIFIED BY 'yourpassword';
$ sudo mysql -u testlink -p testlink
Enter password:yourpassword
~中略~
MariaDB [testlink]> show databases;
MariaDB [testlink]> show grants for 'testlink'@'localhost';
4.nginx設定
$ sudo vi /etc/nginx/conf.d/testlink.conf
---------------------------------------
server{
server_name itestlink.yourdomain;
}
---------------------------------------
$ sudo certbot --nginx -d testlink.yourdomain
Saving debug log to /var/log/letsencrypt/letsencrypt.log
~中略~
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):2
~中略~
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
$ sudo vi /etc/nginx/conf.d/testlink.conf
#以下の内容で作成
-------------------------------------------------------------
upstream phpfpm74{
server unix:/var/run/php/php7.4-fpm.sock;
}
server {
listen 80; # httpへのアクセスをhttpsへリダイレクトする
listen [::]:80;
server_name testlink.yourdomain;
if ($http_x_forwarded_proto != https) {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name testlink.yourdomain;
root /var/www/testlink;
index index.html index.htm index.php;
if ($host != "testlink.yourdomain"){
return 444;
}
index index.html index.htm index.php;
client_max_body_size 1024M;
ssl_stapling on;
ssl_stapling_verify on;
ssl_certificate /etc/letsencrypt/live/testlink.yourdomain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/testlink.yourdomain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
root /var/www/testlink;
index index.php index.html index.htm;
access_log /var/log/nginx/testlink_access.log;
error_log /var/log/nginx/testlink_error.log;
}
location ~ (/logs/|/upload_area/|^/custom/|^/locale/|^/cfg/.*\.js|/\.) {
deny all;
}
location ~ /lib/api/rest/v1/ {
location ~ \.php$ {
if (!-e $request_filename){
rewrite ^(.*)$ / permanent;
}
fastcgi_pass phpfpm74;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
if (!-e $request_filename){
rewrite ^(.*)$ / permanent;
}
}
location ~ \.(php|phar)(/.*)?$ {
root /var/www/testlink;
index index.php index.html index.htm;
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass phpfpm74;
}
}
----------------------------------------------------
#先にindex.phpファイルを置いてphpが動作しているか確認
$ cd /var/www
$ sudo mkdir testlink
$ cd testlink
$ echo -e '' | sudo tee -a index.php
5.TestLinkインストール
$ cd /var/www #$ sudo mkdir testlink #$ sudo chown m-nishimura:m-nishimura testlink $ sudo wget -O "testlink-1.9.20.tar.gz" https://sourceforge.net/projects/testlink/files/TestLink%201.9/TestLink%201.9.20/testlink-1.9.20.tar.gz/download $ sudo tar xvzf testlink-1.9.20.tar.gz $ sudo chown -R www-data:www-data testlink-1.9.20 $ sudo mv testlink-1.9.20 testlink $ sudo rm -Rf testlink-1.9.20.tar.gz $ sudo vi testlink/config.inc.php #以下の通り編集
-----------------------------------
**
* TL_REPOSITORY_TYPE_FS: the where the filesystem repository should be located
* We recommend to change the directory for security reason.
* (see http://itsecuritysolutions.org/2012-08-13-TestLink-1.9.3-multiple-vulnerabilities/)
* Put it out of reach via web or configure access denied.
*
**/
$g_repositoryPath = '/var/www/testlink/upload_area/'; /* /var/www/testlinkに変更 */
if (($upa = getenv('TESTLINK_UPLOAD_AREA'))) {
$g_repositoryPath = trim($upa);
~略~
/**
* @var string Path to store logs -
* for security reasons (see http://itsecuritysolutions.org/2012-08-13-TestLink-1.9.3-multiple-vulnerabilities/)
* put it out of reach via web or configure access denied.
*/
$tlCfg->log_path = '/var/www/testlink/logs/'; /* /var/www/testlinkに変更 */
if (($lp = getenv('TESTLINK_LOG_PATH'))) {
$tlCfg->log_path = trim($lp);
}
-----------------------------------
# http://testlink.yourdomainにアクセスしてインストーラ実行 # インストール完了後に作業 $ cd /var/www/testlink $ sudo cp -R custom_config.inc.php.example custom_config.inc.php $ sudo vi custom_config.inc.php #下記の部分をコメントアウト解除
---------------------------------------
// SMTP server Configuration ("localhost" is enough in the most cases)
$g_smtp_host = 'localhost'; # SMTP server MUST BE configured
# Configure using custom_config.inc.php
$g_tl_admin_email = 'root'; # for problem/error notification
$g_from_email = 'testlink_srv@localhost'; # email sender
$g_return_path_email = 'testlink_sev@localhost';
---------------------------------------
#日本語化する #ユーザの言語をJapaneseにすれば日本語化される #不要ディレクトリ削除 $ sudo rm -fr /var/www/testlink/install #アップロードファイル保管先変更 $ sudo cat /etc/passwd ---------------------------------------------------------- www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin ---------------------------------------------------------- #移動先ディレクトリ確認 $ sudo ls -al /mnt/testlink/ 合計 8 drwxr-xr-x 6 root root 4096 2月 17 12:07 . drwxr-xr-x 4 root root 4096 2月 16 18:15 .. drwx------ 2 postgres postgres 0 7月 27 2021 database drwxrwxrwx 2 systemd-coredump systemd-coredump 0 5月 21 2021 redmine drwx------ 2 mysql mysql 0 2月 16 13:23 testlink-database drwxrwxrwx 2 www-data www-data 0 2月 17 12:12 testlink-file #ファイルコピー $ cd /var/www/testlink/upload_area/ $ sudo cp -Rp .* /mnt/testlink/testlink-file/ $ sudo du -s /var/lib/mysql/* $ sudo cp -Rp ._* /mnt/testlink/testlink-file $ sudo cp -Rp .dir /mnt/testlink/testlink-file $ sudo cp -Rp .htaccess /mnt/testlink/testlink-file $ ls -al /mnt/testlink/testlink-file #元ディレクトリ退避 $ sudo mv /var/www/testlink/upload_area /var/www/testlink/bk_upload $ sudo ln -s /mnt/testlink/testlink-file /var/www/testlink/upload_area $ sudo ls $ sudo rm -rf /var/www/testlink/bk_upload #グラフ文字化け対応 $ sudo apt-get update $ sudo apt-get install -y fonts-ipafont fontconfig $ fc-cache -fv $ fc-list | grep -i ipa /usr/share/fonts/opentype/ipafont-mincho/ipam.ttf: IPA明朝,IPAMincho:style=Regular /usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf: IPA Pゴシック,IPAPGothic:style=Regular /usr/share/fonts/opentype/ipafont-mincho/ipamp.ttf: IPA P明朝,IPAPMincho:style=Regular /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf: IPAゴシック,IPAGothic:style=Regular /usr/share/fonts/truetype/fonts-japanese-mincho.ttf: IPA明朝,IPAMincho:style=Regular /usr/share/fonts/truetype/fonts-japanese-gothic.ttf: IPAゴシック,IPAGothic:style=Regular $ sudo vi /var/www/testlink/custom_config.inc.php
#最終行に追加 -------------------------------------- // $tlCfg->req_spec_template->scope->value = 'c:\usr\local\xampp-1.7.2\xampp\htdocs\head-20090909\item_templates\req_spec.txt'; $tlCfg->charts_font_path = "/usr/share/fonts/truetype/fonts-japanese-gothic.ttf"; ?> --------------------------------------
◆参考サイト
・PHPインストール
https://symfoware.blog.fc2.com/blog-entry-2448.html
https://tomato-develop.com/ubuntu-20-04-nginx-mariadb-wordpress-setup/
・nginx設定
https://hacknote.jp/archives/3090/
https://forum.testlink.org/viewtopic.php?t=6930
・TestLinkインストール
https://qiita.com/shoooo/items/01682a255448c2b4ecd3
https://thusharapriyantha.blogspot.com/2015/04/install-testlink-1913-stormbringer-in.html
・MariaDBデータ移動
https://tomato-develop.com/ubuntu-20-04-nginx-mariadb-wordpress-setup/
https://minory.org/mysql-change-datadir.html
コメント