ラベル 技術メモ の投稿を表示しています。 すべての投稿を表示
ラベル 技術メモ の投稿を表示しています。 すべての投稿を表示

ディレクトリ、パス、フォルダ

一応は理解していると思っている「ディレクトリ」「パス」「フォルダ」の意味
自分の中で意味の定義をまとめようと思い調べてみると、よくわからなくなってきた

間違えているかもしれないが
個人的に以下定義で行くことにする

例) C:\Users\User\Download\test.txt

1.フォルダ
ファイルや他フォルダを格納する入れ物
例では "users"、"user"、"download" がフォルダに相当

2.ファイル
ファイル、としか説明のしようがない
例では "test.txt" がファイルに相当

3.パス
ファイルやフォルダの経路
例では C:\Users\User\Download や C:\Users といったフォルダまでの経路と
C:\Users\User\Download\test.txt といったファイルまでの経路

4.ディレクトリ
フォルダまでの経路をディレクトリと呼ぶことにする = ディレクトリパス
例では C:\Users\User\Download や C:\Users といったフォルダまでの経路

間違えてるかな…


技術メモ

PHP:Excel_Reviserが動作しない

とあるシステムの新インフラ化作業を行っているが、Excel_Reviserなるライブラリが新環境で動作しない。


Excel_Reviser
PHPを用いたEXCELファイル編集用ライブラリーらしいが開発休止中

環境

旧環境:PHP 5.2.8 / Windows 32bit / SJIS
新環境:PHP 7.4.6 / Windows 64bit / UTF-8 (XAMPPで構築)
reviserのバージョン:0.24 beta 2008/01/13

現象(1)

reviser.phpのincludeでエラーとなる。
Deprecated: Array and string offset access syntax with curly braces is deprecated

■原因
asc2utf関数内で配列要素を { } で指定していた。

■対応
[ ] に変更する。

変更前:
$utfname.=$ascii{$i}."\x00";

変更後:
$utfname.=$ascii[$i]."\x00";


現象(2)

includeで別のエラー
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Excel_Reviser has a deprecated constructor

■原因
クラス名とコンストラクタ名が同じ "Excel_Reviser" のため。

■対応
コンストラクタ名を "__construct" へ変更する。

変更前:
function Excel_Reviser(){

変更後:
function Excel_Reviser__construct(){


現象(3)

get_magic_quotes_runtime関数でエラー
Deprecated: Function get_magic_quotes_runtime() is deprecated

■原因
「この関数は PHP 7.4.0 で 非推奨になります。この関数に頼らないことを強く推奨します。」とのこと。

■対応
とりあえず 関数削除し false をセットするように修正。

変更前:
$this->Flag_Magic_Quotes = get_magic_quotes_runtime();

変更後:
$this->Flag_Magic_Quotes = false;


現象(4)

Excelのオープン処理でエラー
ERROR file(~) is broken (ExBlock)

■原因
不明
Excelファイルヘッダのチェックでもやっているんだろうか?

■対応
よくわからないので全てコメントアウト

現象(5)

__to_utf16関数の呼び出しでエラー
Notice: Only variables should be passed by reference

■対応
__to_utf16関数の第1引数 &%str の "&" を除去する。

変更前:
function __to_utf16(&$str,$opt=0)

変更後:
function __to_utf16($str,$opt=0)


上記1~5の対応で何となく動いたので良しとする


技術メモ, PHP, reviser

Docker #5:Docker Hubへの登録 (2)

https://docs.docker.com/get-started/part3/

Docker Hubにレポジトリを作成

1) https://hub.docker.com/ にログイン

2) 上部メニューの[Repositories] より [Create Repository] をクリック

3) Create Repositoryの画面が開いたら、Name欄に「bulletinboard」と入力し [Create] ボタンをクリック

Docker Hubへのプッシュ

1) Docker Quickstart TerminalでDocker Hubにログインしておく

2) 以下コマンドを実行
user@DESKTOP-G1NPCN1 MINGW64 /d/Program Files/Docker Toolbox/node-bulletin-board/bulletin-board-app (master)
$ docker tag bulletinboard:1.0 xxxxxxxx/bulletinboard:1.0

$ docker push xxxxxxxx/bulletinboard:1.0
The push refers to repository [docker.io/xxxxxxxx/bulletinboard]
 :
user@DESKTOP-G1NPCN1 MINGW64 /d/Program Files/Docker Toolbox/node-bulletin-board/bulletin-board-app (master)
$
※ xxxxxxxx はDocker ID



技術メモ, Docker

■ Ubuntu学習 #6:MySQL使ってみる



第2回 MySQLにはじめてのデータを入れてみる:MySQL道普請便り|gihyo.jp … 技術評論社

上記サイトのサンプルデータその3をやってみたがエラーでインポートできなかった。
mysql> LOAD DATA INFILE '/tmp/KEN_ALL_UTF8.CSV' INTO TABLE zipcode.zipcode FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (code, old_zipcode, zip_code, prefecture_kana, city_kana, town_kana, prefecture, city, town, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy);
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql>

既定では決められた場所以外からのインポートはできない模様
@@global.secure_file_prev を確認
mysql>  SELECT @@global.secure_file_priv;
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/     |
+---------------------------+
1 row in set (0.00 sec)

上記のようになっているので
インポート対象のファイルは /var/lib/mysql-files/ に置く必要がある

ということで、ファイルをコピーし、
user@user:~$ sudo cp /tmp/KEN_ALL_UTF8.CSV /var/lib/mysql-files/

LOAD DATAのパスを変更しインポート
mysql> LOAD DATA INFILE '/var/lib/mysql-files/KEN_ALL_UTF8.CSV' INTO TABLE zipcode.zipcode FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (code, old_zipcode, zip_code, prefecture_kana, city_kana, town_kana, prefecture, city, town, @dummy, @dummy, @dummy, @dummy, @dummy, @dummy);
Query OK, 124433 rows affected (4.73 sec)
Records: 124433  Deleted: 0  Skipped: 0  Warnings: 0



技術メモ, Linux, Ubuntu, MySQL

Ubuntu:#5 MySQL初期設定

"mysql_secure_installation" コマンドで初期化を行う

user@user:~$ sudo mysql_secure_installation
[sudo] user のパスワード:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:
VALIDATEP PASSWORDコンポーネントをセットアップしますか?
→ "y"

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
パスワード検証ポリシーを選択
STRONGが最も強力だが、今回は面倒なので"LOW"(0)を選択

Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
パスワード強度は 50 とのこと。
問題ないので "y" で続行

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) :
匿名ユーザーを削除するか? "y" を入力

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? (Press y|Y for Yes, any other key for No) :
リモートからのrootログインを禁止するか?
本当は"y"が良いと思われるが、今回はテストなので "n" を入力

By default, MySQL 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? (Press y|Y for Yes, any other key for No) :
"test"データベースを削除するか?
使わないので "y" を入力

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

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
特権テーブルを今すぐ再ロードするか?
どちらでも良さそう。"y" を入力

これで終了

SSHでMySQLにrootで接続してみる。
user@user:~$ sudo mysql -u root -p
[sudo] user のパスワード:
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.20-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

※ mysqlコマンドは "sudo" を付けないと実行できない



技術メモ, Linux, Ubuntu, MySQL

Ubuntu:#4 WindowsからSSHで接続

Ubuntu側のネットワーク、SSHサーバーインストールが完了したので、ホストOSのWindowsからSSHで接続してみる。

Windows側にSSHクライアントをインストールしておくこと
SSH:Windows10:Windows10標準のSSHクライアントを使う

コマンドプロンプトで"ssh"コマンドを実行
C:\Users\user>ssh 192.168.1.50
The authenticity of host '192.168.1.50 (192.168.1.50)' can't be established.
ECDSA key fingerprint is SHA256:OfecYNuvbQmhBtY4Wu9divhRi5qH6SiEb96rAewIglY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.50' (ECDSA) to the list of known hosts.
Connection closed by 192.168.1.50 port 22

C:\Users\user>

初回は上記のようになる
2回目以降、"-l" パラメータでログインユーザーも指定してログイン
C:\Users\user>ssh -l user 192.168.1.50
user@192.168.1.50's password:
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-37-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


0 updates can be installed immediately.
0 of these updates are security updates.

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Sat Jun 13 19:39:45 2020 from 192.168.1.102
user@user:~$ ls
ダウンロード  テンプレート  デスクトップ  ドキュメント  ビデオ  ピクチャ  ミュージック  公開
user@user:~$



技術メモ, Linux, Ubuntu, SSH

技術メモ:リダイレクト

5分で一通り理解できる!Linuxのリダイレクト 使い方と種類まとめ

リダイレクト先:
・標準入力 (0)
・標準出力 (1)
・標準エラー出力 (2)

カッコ内の数値は "割り振り番号"識別子 (Linuxの場合のデフォルト値)

標準出力をリダイレクトするには "> ファイル名" を指定する。
echo Hello_World > Test_Hello_World.txt

エラーは標準出力に出力されない
標準エラー出力を出力するには "2> ファイル名" のように 標準エラー出力の識別子 "2" を指定する。

標準出力と標準エラー出力を同じとする場合は ">ファイル名 2>1" のように指定する。
= "&> ファイル" でも同様。

出力情報を破棄する場合は、出力先に "/dev/null" を指定する。
$ コマンド >/dev/null 2>&1

入力のリダイレクトは "<" で指定する

"<<" を使うと終端文字列を指定して標準入力を流し込むことができる。

良く使われる例)
$ cat << "EOF" > testfile.txt

"EOF" と入力するまで標準入力をうけつけ、その結果をtestfile.txtにリダイレクトする。



技術メモ, Linux, コマンド, リダイレクト

Hyper-V:#3 Ubuntuインストール

Hyper-V上にUbuntuをインストールしてみる

※ ホストOS : Windows 10 1909 (18363.900)

1) Hyper-V マネージャー を起動

2) "クイック作成" をクリック

3) オペレーティングシステムの選択で "Ubuntu 20.04" を選択し [仮想マシンの作成] をクリック

Hyper-V:#2 VirtualBoxとの共存

Hyper-Vを有効とした環境でVirtualBox(VirtualBox上の仮想マシン)は起動できない。
参考) https://www.virtualbox.org/ticket/19550

Windowsの機能の有効化と無効化で"Hyper-V"のチェックを外すか、
コマンドプロンプト(管理者)で以下コマンドを実行
bcdedit /set {current} hypervisorlaunchtype off

どちらにせよWindowsの再起動が必要

ちなみにHyper-Vを有効にするコマンドは
bcdedit /set {current} hypervisorlaunchtype Auto



技術メモ, Hyper-V, VirtualBox

Windows10:仮想マシンプラットフォーム と ハイパーバイザー プラットフォーム

"Windows ハイパーバイザー プラットフォーム"

"仮想マシン プラットフォーム"

Ubuntu:#3 ネットワーク設定

Ubuntu 20.04 LTS
IPアドレスをDPCPから固定IPに変更したい。

変更後のIPは 192.168.1.50
DNS/ゲートウェイは 192.168.1.1


→ 手順:
/etc/netplan/99_config.yaml を新規作成する
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1]

ファイルを作成したら "sudo netplan apply" を実行

ネットワーク設定(IPアドレス)の確認は、
"ip address show" または
"networkctl status"



技術メモ, Linux, Ubuntu, Network

Ubuntu:#2 SSHサーバーインストール

Ubuntu 20.04 LTS
SSHサーバー(openssh-server)をインストールしてみる

sudo apt install openssh-server


サービス起動確認 (通常はインストールと同時に起動している模様)
systemctl status ssh

※ centosの場合は "systemctl status sshd.service"



技術メモ, Linux, Ubuntu, SSH

Ubuntu:#1 MySQLインストール

OS:Ubuntu 20.04 LTS
MySQLをインストールしてみる

端末より以下コマンドを実行
sudo apt install mysql-server

サービス起動確認 (通常はインストールと同時に起動している模様)
systemctl status mysql

上記コマンドを実行すると "linues 1-13/13 (END)" のような感じでプロンプトが止まる
"q" を押せばコマンドを抜けれる

"Active : active (running)" が表示されていれば起動中
"inactive (dead)" が表示されていれば停止中

停止していたら以下コマンドで起動
systemctl start mysql



技術メモ, Ubuntu, MySQL

技術メモ:Windows 10のエラーコードの意味は?

Windows 10のエラーコードの意味は?

エラーコード一覧
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90

コマンドラインツール
https://www.microsoft.com/en-us/download/details.aspx?id=100432



技術メモ, Windows, エラー

技術メモ:ネットワークが突然不安定になったときの対処法

ネットワークが突然不安定になったときの対処法

PowerShell(管理者) [Win]+[X] - [A] で以下コマンドを実行
netsh winsock reset
netsh int ip reset
ipconfig /flushdns

netsh winsock reset … WinSockの設定情報を初期化
netsh int ip reset … IPアドレス設定を初期化
ipconfig /flushdns … DNSキャッシュを初期化

※Windowsの再起動は無視してよい



技術メモ, Windows, Network

Slim:学習メモ

以下記事を参考にSlimの学習をしているが、サンプルが動作しない。
はじめてのSlimアプリで「Hello World」を表示させよう~動作原理を理解する (1/3):CodeZine(コードジン)

サンプルを起動するとエラーが発生する
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Slim\App::__construct(), 0 passed in C:\xampp\htdocs\firstslim\src\public\index.php on line 11 and at least 1 expected in C:\xampp\htdocs\firstslim\src\vendor\slim\slim\Slim\App.php on line 61

ArgumentCountError: Too few arguments to function Slim\App::__construct(), 0 passed in C:\xampp\htdocs\firstslim\src\public\index.php on line 11 and at least 1 expected in C:\xampp\htdocs\firstslim\src\vendor\slim\slim\Slim\App.php on line 61

サンプルのSlimバージョンは "3.11" のようだが、自分の環境は"4.5"がインストールされていた。
Slim3とSlim4では、いろいろと仕様変更がある模様。

composer.jsonを変更し、Slim3系のバージョンを使用するように設定

変更前:
{
    "require": {
        "slim/slim": "^4.5"
    }
}

変更後:
{
    "require": {
        "slim/slim": "3.*"
    }
}

そして "composer update" コマンドを実行
C:\xampp\htdocs\firstslim\src>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 1 update, 4 removals
  - Removing psr/log (1.1.3)
  - Removing psr/http-server-middleware (1.0.1)
  - Removing psr/http-server-handler (1.0.1)
  - Removing psr/http-factory (1.0.1)
  - Installing pimple/pimple (v3.3.0): Loading from cache
  - Downgrading slim/slim (4.5.0 => 3.12.3): Loading from cache
Writing lock file
Generating autoload files

Slim3.12.3がインストールされた。

サンプルを実行してみる。
→ 正常動作した


技術メモ, PHP, Slim

XAMPP+MySQL+mroonga #9 データベースの切り替え

データベースを切り替えるには "use データベース名" で行う

例) testdb への切り替え
MariaDB [(none)]> use testdb
Database changed
MariaDB [testdb]>



技術メモ, XAMPP, MySQL, mroonga

XAMPP+MySQL+mroonga #8 mroongaの設定

mroongaが使えるか show engines コマンドで確認

Setting environment for using XAMPP for Windows.
xxx@xxx c:\xampp
# cd mysql

xxx@xxx c:\xampp\mysql
# bin\mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.22-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show engines;
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                          | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | Stores tables as CSV files                                                       | NO           | NO   | NO         |
| MRG_MyISAM         | YES     | Collection of identical MyISAM tables                                            | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                        | NO           | NO   | NO         |
| MyISAM             | YES     | Non-transactional engine with good performance and small data footprint          | NO           | NO   | NO         |
| SEQUENCE           | YES     | Generated tables filled with sequential values                                   | YES          | NO   | YES        |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, foreign keys and encryption for tables | YES          | YES  | YES        |
| Aria               | YES     | Crash-safe tables with MyISAM heritage                                           | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                               | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.000 sec)

MariaDB [(none)]>

Engine欄に "Mroonga" が表示されていれば良いが、無さそうなのでインストールする。

MariaDB [(none)]> install plugin mroonga soname 'ha_mroonga';
Query OK, 0 rows affected (0.013 sec)

MariaDB [(none)]> show engines;
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                          | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | Stores tables as CSV files                                                       | NO           | NO   | NO         |
| MRG_MyISAM         | YES     | Collection of identical MyISAM tables                                            | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                        | NO           | NO   | NO         |
| MyISAM             | YES     | Non-transactional engine with good performance and small data footprint          | NO           | NO   | NO         |
| SEQUENCE           | YES     | Generated tables filled with sequential values                                   | YES          | NO   | YES        |
| Mroonga            | YES     | CJK-ready fulltext search, column store                                          | NO           | NO   | NO         |
| Aria               | YES     | Crash-safe tables with MyISAM heritage                                           | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                               | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, foreign keys and encryption for tables | YES          | YES  | YES        |
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.000 sec)

MariaDB [(none)]>



技術メモ, XAMPP, MySQL, mroonga

XAMPP+MySQL+mroonga #7 データベース移行

MySQLのデータベースをmroongaのデータベースへ移行する。

1) mroongaデータベースを停止

2) mroongaプログラムを別フォルダ名に変更
"C:\XAMPP\mysql" → "C:\XAMPP\mysql_mroonga"

3) バックアップしておいたMySQLフォルダ名を元に戻す
"C:\XAMPP\mysql_bak" → "C:\XAMPP\mysql"

4) XAMPP Control PanelよりMySQLを起動

5) XAMPP Control Panelの[Shell]ボタン (またはコマンドプロンプト)

6) mysqldumpコマンドでエクスポート
Setting environment for using XAMPP for Windows.
xxx@xxx c:\xampp
# cd mysql

xxx@xxx c:\xampp\mysql
# bin\mysqldump -u root -r c:\temp\xxx.dmp(バックアップ先ファイル名) --single-transaction データベース名

xxx@xxx c:\xampp\mysql
# 

今度はmroongaを起動
1) MySQLデータベースを停止

2) フォルダ名を変更しmroongaデータベースを有効にする
"C:\XAMPP\mysql" → "C:\XAMPP\mysql_bak"
"C:\XAMPP\mysql_mroonga" → "C:\XAMPP\mysql"

3) mroongaデータベース起動

4) mysqlコマンドでインポート
Setting environment for using XAMPP for Windows.
xxx@xxx c:\xampp
# mysql -u root データベース名 < c:\temp\xxx.dmp(バックアップしたファイル名)
ERROR at line 935: Unknown command '\''.

xxx@xxx c:\xampp
#
エラーが発生した この場合はキャラクタセットの指定が必要らしい utf8を指定してみる
# mysql -u root --default-character-set=utf8 データメース名 < c:\temp\xxx.dmp(バックアップファイル名)

技術メモ, XAMPP, MySQL, mroonga

XAMPP+MySQL+mroonga #6 一般ユーザーを作成

データベースの一般ユーザーを作成する。

create user ユーザー名 identified by 'パスワード';
grant select,insert,update,delete on データベース名.* to ユーザー名;



技術メモ, XAMPP, MySQL, mroonga

その他の記事