Hobby Lab 趣味のモノ作り実験のサイトです。
Software OS RaspberryPi アプリ導入
1.エディタ-の紹介
2.rootパスワードの設定
3.SSHの動作確認
4.FTPインストール
5.Apacheのインストール設定
6.PHP のインストール
 5,6の関係Webページ
7.MySQL他のインストール

Sf:OS関係
SfO:Mint 関係
 PCへMint導入
 アプリ導入
 その他1
 アイコンを作る
SfO:Ubuntu 関係
 PCへUbuntu導入
 アプリ導入
SfO:RaspberryPi 関係
はじめに
 RaspberryPiへOS導入
 アプリ導入
 Programming
シェル・コマンド関係
 LXTerminal
 sed
 i2ctools
I/O・アプリ関係
 RealVNCとViewer
 IO動作確認
 MySQL
 Python
 raspberrypiハード
Sf:Server 関係
SfS:レンタルサーバー
 CORE-X
SfS:Windowsサーバー
 XAMPPの概要と導入
 Note XAMPP
 Note XAMPP Err
 Note Apache
 Note PHP
 Note MyQSL
Sf:Programming関係
C 関係
 C言語でプログラムミング
Python 関係
はじめに
 RaspberryPi開始
 Windows開始
共通事項
 プログラミングNote
 パッケージ導入 pip
 標準ライブラリ
 Serialライブラリ
 SMBusライブラリ
HTML関係
 開始とNote
Sf:IDE 開発環境
SfI:STM32
 STM32CubeIDEでプログラム
 HALと直接レジスター操作の速度
SfI:CH32
 MounRiver Studioでプログラム
SfI:Arduino
各ボード毎の設定
 Uno 設定
 Mega2560 設定
 DUE_CH340 設定
 ESP_WROOM02 設定
 ESP12F_D1mini 設定
 ESP32 設定
 CH32V 設定
ライブラリー
 OneWire使い方
その他
 日本語リファレンス(外部リンク)
 WiFi Macアドレスを調査
Sf:AP アプリ関係
SfA:エディタ
SfA:回路図CAD
SfA:回路シミュレータ
 シミュレーションの設定
 色の設定
 電源設定設定
SfA:リモートソフト
Sf:Pt プロトコル関係
SfPt:MODBUS
Sf:Otgers その他

1.エディターの紹介

エディターの紹介 nano
 https://www.nano-editor.org/dist/latest/nano.html

エディターの操作
カーソルを右に動かす キーボード カーソルキー →
カーソルを左に動かす キーボード カーソルキー ←
カーソルを上に動かす キーボード カーソルキー ↑
カーソルを下に動かす キーボード カーソルキー ↓

デリートキーで文字を消して、入力した文字がそのままテキストファイルに記入されるっぽい。

ファイルの保存が Ctrl + S
エディタの終了が Ctrl + X

ワード検索 Ctrl + W




2.rootパスワードの設定

sudo passwd root
その後2回パスワードを入力して完了!




3.SSHの動作確認

  Windowsのターミナルを起動し下記画面が出るので、操作する。
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows

PS C:\Users\asovo>
ssh tryday@192.168.10.114 ・・・①
The authenticity of host '192.168.10.114 (192.168.10.114)' can't be established.
ED25519 key fingerprint is SHA256:
・・・・・・・・・・・・・・・・・・・・・・・・.・・・②
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
y・・・③
Please type 'yes', 'no' or the fingerprint:
yes・・・④
Warning: Permanently added '192.168.10.114' (ED25519) to the list of known hosts.
tryday@192.168.10.114's password:
********・・・⑤
Linux tryday 6.1.21-v7+ #1642 SMP Mon Apr3 17:20:52 BST 2023 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu May2 15:59:15 2024
tryday@tryday:~ $
exit・・・⑥
ログアウト
Connection to 192.168.10.114 closed.
PS C:\Users\asovo>


  黄緑色がキー入力内容です。
①は ログインするユーザー名 @ sshサーバのIPアドレス
②のピンク色の部分が公開鍵です。
③はご入力で yse と入力する必要があったが、 y としか入力しなかったので、④でyseと入力
⑤は表示が有りませんが、 ユーザーのパスワードを入力しています。
⑥はリモート接続されているがすぐログオフ=exit した状況で、Windowsのターミナル初期表示に戻った!
公開鍵に変更する場合は 
 https://monoist.itmedia.co.jp/mn/articles/1912/11/news022_3.html




4.FTPインストール

sudo apt-get install vsftpd
OS起動時にFTPdも自動起動するようにします。
sudo systemctl enable vsftpd
設定せずにFTPソフトで接続した場合、書き込みが出来ないので、最低限の設定する。 550 Permission denied.
コマンドが受け付けられません.
アップロードを中止しました.
とFTTPのメッツセージが出て書き込むことが出来ない。
なおディレクトリの変更も出来ないか確認!現在は/home/trydayになっている。
ここをアパッチのhttpdに変更しても良いが

設定ファイルを編集
vsftpdの設定ファイルを編集します。
sudo vi /etc/vsftpd.conf
コメント#を消去する。
# write_enable=YES
保存して終わる
:w
:q

または
:wq
OSを再起動する。
※サービスと再起動[ service vsftpd start ]しても反映されません。注意




5.Apacheのインストールと設定

a.インストール
まず、ターミナルに次のコマンドを入力して、使用可能なパッケージを更新します。 
sudo apt update
次に、次のコマンドでパッケージをインストールします。apache2
sudo apt install apache2 -y
インストールが終われば試してみる。
他のコンピュータでIPアドレスを打ち込むと
Apache2が表示される。

初期の設定は /var/www/html/ にindex.htmlがある。

b.設定ファイルの変更
ユーザー名 tryday の場合、/home/tryday のディレクトリー以降がFTPで管理出来ます。
このため、Webのデータ(HTML等)の保管場所を www/html/ 以降に保管しようと思い、apache2の設定を変更します。
 (a)ドキュメントルート
変更はRaspberry Piの端末エミュレータから ルート権限でエディターを起動して修正下さい。
tryday@tryday:~ $ su root
パスワード:
root@tryday:/home/tryday# geany
/etc/apache2/sites-available の 000-default.conf の中を変更します。
DocumentRoot /var/www/html
           ↓
# DocumentRoot /var/www/html
DocumentRoot /home/tryday/www/html
 (b)ディレクトリー
  /etc/apache2 の apache2.conf の中を変更します。
<Directory /var/www/>
           ↓
# <Directory /var/www/>
<Directory /home/tryday/www/>
 (c)apacheの再起動
  Raspberry Piの端末エミュレータから ルート権限でapacheを再起動します
root@tryday:/home/tryday# sudo /etc/init.d/apache2 restart

c.パーミッションの変更
HTMLデータをFTPで転送したあと、各ディレクトリーやファイルのパーミッションを下記の様に設定下さい。
ディレクトリー 705又は755
ファイル 604又は644
PHPファイル 705又は755




6.Apache 用の PHP のインストール

ApacheサーバーがPHPファイルを処理できるようにするには、最新バージョンのPHPとApache用のPHPモジュールをインストールする必要があります。次のコマンドを入力して、これらをインストールします。
tryday@tryday:~ $sudo apt install php libapache2-mod-php -y
(2)(3)関係のURL
https://www.raspberrypi.com/documentation/computers/remote-access.html




7.MySQLとPHPMyAdminをインストール

a.MariaDB導入
https://qiita.com/mono_taro/items/affac9438146ab307bf4
MariaDB導入
まずはsudo apt updateをする。
で、MariaDBを導入する。
tryday@tryday:~ $ sudo apt update
tryday@tryday:~ $ sudo apt install mariadb-server
または
tryday@tryday:~ $ sudo apt update
tryday@tryday:~ $ sudo apt install -y mariadb-server
b.phpMyAdminの導入
MariaDBの導入が出来たら次はphpMyAdminを導入する。
tryday@tryday:~ $ sudo apt install phpmyadmin
設定画面が出てくるので、「apache2」にチェックを入れ、「yes」「ok」で進み、パスワードを入力する。
※MariaDBの設定が済んでいればパスワードの設定は必要なし?

ログイン
http://192.168.*.*/phpmyadminでphpMyAdminのログインページを開く
ユーザー名「root」,パスワードは設定したものを使う。
c.ユーザー他設定
mysql_secure_installationというツールを使ってユーザー権限等を書き換え
tryday@tryday:~ $ 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]n ・・・③
... skipping.

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] y ・・・⑦
... 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] n ・・・⑧
... skipping.

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] y ・・・⑨
- 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] y ・・・⑩
... 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!
tryday@tryday:~
ローカルからのアクセスに限定する行をコメントアウトします。
tryday@tryday:~ $ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
ファイル中のbinde-addressの行を次の通りコメントアウトします。
# binde-address =127.0.0.1
①MariaDBにログインして外部端末からのアクセスを許可します。
②rootパスワードを入力し、権限変更のコマンドを入力。
③mysqlから外れる
④MariaDBを再起動して完了
tryday@tryday:~ $ mysql -u root -p ・・・①
Enter password:
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.5.23-MariaDB-0+deb11u1 Raspbian 11

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)]> grant all privileges on *.* to root@"%" identified by '**********' with grant option; ・・・②
Query OK, 0 rows affected (0.009 sec)

MariaDB [(none)]> exit ・・・③
Bye
tryday@tryday:~ $ sudo systemctl restart mysql ・・・④
tryday@tryday:~ $
phpmyadminを動作させる
/etc/apache2/apache2.confの最下行に以下を追記
Include /etc/phpmyadmin/apache.conf
修正後apacheを再起動します。
root@tryday:/home/tryday# sudo /etc/init.d/apache2 restart
Restarting apache2 (via systemctl): apache2.service.
root@tryday:/home/tryday#
これで Webクライアントから localhost/phpmyadmin/index.php で phpmyadmin が表示されます。



更新日 2025/11/25 19:37  管理者 平林 剛Hirabayashi Takeshi