|
コマンドで入力してアプリを導入するものには、『FTP』、『Apache2』、『PHP』、『mysql』、『PHPMyAdmin』が挙げられる。
その前に最初に実施するのは root のパスワードを設定する。
(1)rootのパスワード設定
|
sudo passwd root
|
|
その後2回パスワードを入力して完了! |
(2)FTP Serverの導入
|
sudo apt-get install vsftpd |
OS起動時にFTPdも自動起動するようにします。
sudo systemctl enable vsftpd |
設定せずにFTPソフトで接続した場合、書き込みが出来ないので、最低限の設定する。
550 Permission denied.
コマンドが受け付けられません.
アップロードを中止しました.
とFTTPのメッツセージが出て書き込むことが出来ない。
なおディレクトリの変更も出来ないか確認!現在は/home/trydayになっている。
ここをアパッチのhttpdに変更しても良いが
設定ファイルを編集
vsftpdの設定ファイルを編集します。
コメント#を消去する。
保存して終わる
または
OSを再起動する。 ※サービスと再起動[ service vsftpd start ]しても反映されません。注意
|
(3)Web Server Apache2の導入
|
a.インストール
まず、ターミナルに次のコマンドを入力して、使用可能なパッケージを更新します。
次に、次のコマンドでパッケージをインストールします。apache2
sudo apt install apache2 -y |
インストールが終われば試してみる。
他のコンピュータでIPアドレスを打ち込むと
Apache2が表示される。

初期の設定は /var/www/html/ にindex.htmlがある。
b.設定ファイルの変更
設定ファイルの変更はRaspberryPiで変更できたのですが、Ubuntuではできませんでした。
このため、c.パーミッションについて へ進んで下さい。
ユーザー名 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 /home/tryday/www/> |
(c)apacheの再起動
Raspberry Piの端末エミュレータから ルート権限でapacheを再起動します
root@tryday:/home/tryday# sudo /etc/init.d/apache2 restart |
RaspberryPiで変更できたのですが、Ubuntuではできませんでした。
このため、下の c.パーミッションについて から始めて下さい
c.パーミッションについて
|
ここで言うパーミッションとはディレクトリーやファイルのアクセス・読込み、変更・書込み、実行の権限を言います。
権限は『所有者』『グループ』『第三者』の3つに使用者に対し個別に付与できます。
また権限についてはファイルやディレクトリーに対し
r 読む込む事ができる(下表では『読む』)
w 書き込む事ができる(下表では『書く』)
x 実行する事ができる(下表では『実行』)
の3つの動作を組み合わせて下表の様に8つに分けて区別します。
番号 | 記号 | 読む | 書く | 実行 |
0 | --- | × | × | × |
1 | --x | × | × | ○ |
2 | -w- | × | ○ | × |
3 | -wx | × | ○ | ○ |
4 | r-- | ○ | × | × |
5 | r-x | ○ | × | ○ |
6 | rw- | ○ | ○ | × |
7 | rwx | ○ | ○ | ○ |
HTMLデータをFTPで転送したあと、各ディレクトリーやファイルのパーミッションを下記の様に設定下さい。
なお番号の上位から使用者として『所有者』『グループ』『第三者』の権限を示します。 |
|
ディレクトリー |
705又は755 |
ファイル |
604又は644 |
PHPファイル |
705又は755 |
|
d.シンボリックリンク
|
apache2,confに記載のhtmlを格納するディレクトリトーは /var/www/html/ です。
このディレクトリーを私の /home/hobbylab/www/html/からアクセスするために、
/var/www/html/ を/home/hobbylab/www/html/へシンボリックリンクします。
①/home/hobbylab/www/html/ の htmlディレクトリーを削除します。
②/var/www/html/ の htmlディレクトリーを削除します。
③/var/www/ の www/ディレクトリーのパーミッションを777に変更します。
④所有者 hobbylab で /var/www/にhtml/ディレクトリーを作成します。
このhtml/ディレクトリーをhome/hobbylab/www/html/にシンボリックリンクします。
⑤コマンドで cd /home/hobbylab (以下シンボリックするディレクトリーへ移動する)
ln -s /var/www/html www/html と入力実行する。
⑥/var/www/ の www/ディレクトリーのパーミッションを755へ戻す。
以上で/home/hobbylab/www/html/からファイルやディレクトリーを作成でき、apacheサーバーを通して、
webブラウザでアドレスlocalhostを指定すれば、見ることができるようになります。
|
|
(5)mysqlの導入
|
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 |
|
(6)PHPMyAdminの導入
|
MariaDBの導入が出来たら次はphpMyAdminを導入する。
tryday@tryday:~ $ sudo apt install phpmyadmin |
設定画面が出てくるので、「apache2」にチェックを入れ、「yes」「ok」で進み、パスワードを入力する。
※MariaDBの設定が済んでいればパスワードの設定は必要なし?
ログインするためのユーザー設定を行う
このログインは
http://192.168.*.*/phpmyadminでphpMyAdminのログインページを開く
この時に使用するユーザー名「root」,パスワードは設定したものを使う。
ユーザー他設定
ysql_secure_installationというツールを使ってユーザー権限等を書き換え
コマンド確認のこと
tryday@tryday:~
$ sudo mariadb-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 が表示されます。
|
|