# ラズパイでWebserver 必要なもの (例えば) Web server: Apache DB: MySQL サーバサイドスクリプト: PHP <!--コンテンツ管理ツール:WordPress --> ほかに,Web serverとしてnginx,DBとしてPostgreSQLでも良いし, CSSやJSでページ記述しても良いですよ. ## apache2の導入と起動 ```sh $ sudo apt install apache2 $ sudo service apache2 restart ``` ## とりあえず以下を`index.html`で保存 ```htmlembedded <html> test </html> ``` ```shell $sudo cp intex.html /var/www/html/ ``` あとはブラウザを開いて,`http://localhost/`で確認. # スマホから確認 ## SSID 'HSP' に接続 Passwd: 2025oc0802 RaspberryPiでIPアドレスを確認 ```shell $ ifconfig ``` ``` wlan0: flag... inet 192.186.11.x <= このxを確認. ``` ## スマートフォンも SSID 'HSP' に接続 Passwd: 2025oc0802 Webブラウザで `192.268.11.x` を開く. ![image](https://hackmd.io/_uploads/HkKHeGA3lg.png) # 以下はいろいろやりたい人向け ## PHPの導入 ```sh $ sudo apt install php mariadb-server ``` ## MySQLの導入 ```sh $ sudo apt install php-mysql ``` ## MySQLの起動 ```sh $ sudo systemctl enable mariadb $ sudo systemctl start mariadb ``` ## PHPバージョン確認 ```sh $ php -v PHP 8.4.11 (cli) (built: Aug 3 2025 07:32:21) (NTS) Copyright (c) The PHP Group Zend Engine v4.4.11, Copyright (c) Zend Technologies with Zend OPcache v8.4.11, Copyright (c), by Zend Technologies ``` この場合だと8.4です. ## 追加パッケージ ```sh $ sudo apt install php8.4-xml $ sudo apt install php8.4-gd $ sudo apt install php8.4-curl $ sudo apt install php8.4-dom $ sudo apt install php8.4-mbstring $ sudo apt install php8.4-zip $ sudo apt install php8.4-imagick ``` <!-- ```sh $ sudo mysql ``` ``` MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '設定したルートのパスワード'; Query OK, 0 rows affected (0.0xx sec) MariaDB [(none)]> flush privilages; Query OK, 0 rows affected (0.0xx sec) MariaDB [(none)]> CREATE DATABASE wordpress; Query OK, 1 row affected (0.0xx sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO '【mysqlのユーザ】'@'localhost' IDENTIFIED BY '【mysqlのパスワード】'; MariaDB [(none)]> exit Bye ``` ```sh $ cd /var/www/html $ sudo rm * $ sudo wget https://ja.wordpress.org/latest-ja.tar.gz $ sudo tar xvfz latest-ja.tar.gz $ sudo mv wordpress/* . $ sudo rm -rf wordpress latest-ja.tar.gz $ sudo reboot ``` --> [PC側の設定へ](https://hackmd.io/z-Zp_bfyRO2nQqWzd27nBA?view)