アパッチのインストール要領
①LXTerminalを起動する。
②pi@raspberrypi:~ $ sudo apt-get update
③pi@raspberrypi:~ $ sudo apt-get install apache2
これで完了。
次に正しくインストールされたか確認します。
ifconfig若しくはipaで端末のIPアドレスを調べる
webブラウザで「http://(端末IPアドレス)」でapache2デフォルトページが表示されたらOK
ラズパイと同じwifiに接続しているスマホからもアクセスできます。
htmlファイルを作成する。
/var/www/htmlディレクトリ内のファイルを表示しているので、ここにファイルを作成する。
「cd」コマンドでwwwディレクトリに移動する。
pi@raspberrypi:~ $ cd /var/www
「ls」コマンドでwwwディレクトリ内のデータを確認する。(オプション「-la」で権限がみれます。)
「html」ディレクトリがあるのが確認できます。
pi@raspberrypi:~ $ /var/www $ ls -la
drwxr-xr-x 3 root root 4096 2月 16 09:22 .
drwxr-xr-x 12 root root 4096 2月 16 09:22 ..
drwxr-xr-x 2 root root 4096 2月 16 09:22 html ←ここ
「chmod」コマンドで「html」ディレクトリのアクセス権を変更する
pi@raspberrypi:~ $ /var/www $ sudo chmod 777 html/
pi@raspberrypi:~ $ /var/www $ ls -la
drwxr-xr-x 3 root root 4096 2月 16 09:22 .
drwxr-xr-x 12 root root 4096 2月 16 09:22 ..
drwxrwxrwx 2 root root 4096 2月 16 09:22 html ←変更できました
「html」に移動します
pi@raspberrypi:~ $ cd /var/www/html
「hello-world.html」ファイルを作成
pi@raspberrypi:~ $ touch hello-world.html
「hello-world.html」ファイルを「vi」で編集
pi@raspberrypi:~ $ vi hello-world.html
----------------------------------------------------
<body>
<b>hello world</b>
</body>
----------------------------------------------------
viの操作コマンド↓
行削除「dd」
文字削除「x」
文字入力「i」「a」
保存終了「:wq」
終了「:q」
強制終了「:q!」
viが難しい場合は、デスクトップ左上のフォルダのアイコンをクリックして、「/」→「var」→「www」→「html」に移動して右クリック→「新規作成」→「空のファイル」→「hello-world.html」という名前でファイルを作成→そのファイルを右クリック→「アプリケーションで開く」→「TextEditor」クリックして編集→保存
webブラウザで「http://(端末IPアドレス)/hello-world.html」で[hello world]が表示されたらOK
(ユーザ www-data をグループ i2c に追加)
pi@raspberrypi:~ $ sudo gpasswd -a www-data i2c
(ユーザ www-data をグループ gpio に追加)
pi@raspberrypi:~ $ sudo gpasswd -a www-data gpio
うまくいかない時はアパッチを再起動してみましょう。
アパッチを再起動
pi@raspberrypi:~ $ sudo service apache2 restart