Vagrant+VirtualboxでVyOSを複数台作る
前提
VyOSルーター3台を作成+疎通できるようにする(端同士のルーターは疎通出来なくてよいとする)
環境
- Windows10
- VirtualBox 7.0.14
- Vagrant 2.4.1
構成図

今回はPC部分無し。
真ん中のルーター三台を作成する。
左から「vyos1」「vyos2」「vyos3」とする。
Vagrant box 取ってくる
この辺を取ってくる。
Vagrant box vyos/current - Vagrant Cloud
下記コマンドで初期化+Vagrantfile作成
$vagrant init vyos/current
Vagrantfileがあるか確認。
$ ls -al total 16 drwxr-xr-x 1 orin 197121 0 Mar 10 16:34 ./ drwxr-xr-x 1 orin 197121 0 Mar 9 23:49 ../ drwxr-xr-x 1 orin 197121 0 Mar 10 02:08 .vagrant/ -rw-r--r-- 1 orin 197121 4390 Mar 10 08:25 Vagrantfile
Vagrantfileをいじる
今回は三つ作りたいので三台分の設定を書く。
$vim Vagrantfile
以下、設定内容。
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "vyos/current"
config.vm.define :vyos1 do | vyos1 |
vyos1.vm.hostname = "vyos1"
vyos1.vm.network :private_network, ip: "192.168.0.1" , virtualbox__intnet: "intnet1"
vyos1.vm.network :private_network, ip: "192.168.1.254" , virtualbox__intnet: "intnet2"
vyos1.ssh.password= "vyos1"
end
config.vm.define :vyos2 do | vyos2 |
vyos2.vm.hostname = "vyos2"
vyos2.vm.network :private_network, ip: "192.168.1.1" , virtualbox__intnet: "intnet2"
vyos2.vm.network :private_network, ip: "192.168.2.254" , virtualbox__intnet: "intnet1"
vyos2.ssh.password= "vyos2"
end
config.vm.define :vyos3 do | vyos3 |
vyos3.vm.hostname = "vyos3"
vyos3.vm.network :private_network, ip: "192.168.2.1" , virtualbox__intnet: "intnet1"
vyos3.vm.network :private_network, ip: "192.168.3.254" , virtualbox__intnet: "intnet2"
vyos3.ssh.password= "vyos3"
end
.
.
(中略)
.
.
end
ipアドレスとインターフェースをきちんと書いてみた。
また、鍵認証はうまくいかなかったので、パスワード認証にしてみた。
VM起動
下記コマンドを実行して起動する。
$vagrant up vyos1 $vagrant up vyos2 $vagrant up vyos3
・順に起動したらvyos3だけ上手くいかなかったので追記
先にvyos3を起動してみる。
パスワードを求められるので、設定したパスワードを記入してみて、ダメだったら「vyos」(初期パスワード)を記入。
そしたら起動するはず。
起動したか確認
確認コマンドは以下。
$ vagrant status Current machine states: vyos1 running (virtualbox) vyos2 running (virtualbox) vyos3 running (virtualbox)
vyos2でping確認
vyos2 にSSHログイン
$ vagrant ssh vyos2 Welcome to VyOS! ┌── ┐ . VyOS 1.5-rolling-202403080726 └ ──┘ current * Documentation: https://docs.vyos.io/en/latest * Project news: https://blog.vyos.io * Bug reports: https://vyos.dev You can change this banner using "set system login banner post-login" command. VyOS is a free software distribution that includes multiple components, you can check individual component licenses under /usr/share/doc/*/copyright Last login: Sun Mar 10 06:37:25 2024 from 10.0.2.2 vyos@vyos2:~$
ping を回数制限して実行。
configure コマンドで実行モードになろう。
vyos@vyos2:~$ configure [edit] vyos@vyos2#
vyos1(192.168.1.254) と疎通できるか確認。
vyos@vyos2# ping 192.168.1.254 -c 3 PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data. 64 bytes from 192.168.1.254: icmp_seq=1 ttl=64 time=2.28 ms 64 bytes from 192.168.1.254: icmp_seq=2 ttl=64 time=2.32 ms 64 bytes from 192.168.1.254: icmp_seq=3 ttl=64 time=1.98 ms --- 192.168.1.254 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2099ms rtt min/avg/max/mdev = 1.977/2.194/2.321/0.154 ms [edit]
vyos3(192.168.2.1) と疎通できるか確認。
vyos@vyos2# ping 192.168.2.1 -c 3 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=1.52 ms 64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=3.08 ms 64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=2.65 ms --- 192.168.2.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2009ms rtt min/avg/max/mdev = 1.520/2.414/3.075/0.656 ms
最後に(感想)
ひとつのVgrantfileで複数台のVMを作成できることを知った。
vyos3 がうまく起動できない謎は残ったままになってしまって残念。
久しぶりにルーター触れて楽しかった。
【備忘録】WSLが反応しなくなったときの対処メモ
環境
- Windows10
前提
つい数時間前までコマンド実行可能だったのに、PCをシャットダウンして少し寝かせた後、起動したらコマンドを叩いても反応しなくなった
コマンド間違えてる際のhelpさえも出てくれない
やったこと
WSL自身を無効化⇒有効化した
- 設定>アプリ>アプリと機能>プログラムと機能

- Windows の機能の有効化または無効化 をクリック

- Linux用 Windous サブシステム のチェックを外してOKをクリックしてPC再起動

- 次は Linux用 Windous サブシステム をチェックしてOKをクリックしPC再起動
動作確認
> wsl --list -v NAME STATE VERSION * Ubuntu-22.04 Stopped 2
適当なコマンドを叩いて上記のように結果が出力されたらOK!
WSL でよく使うコマンド
環境
- Windows10
目的
WSL(2) を簡単に起動、停止、消去、などできるように纏めたい
コマンド一覧
- バージョン確認
>wsl -l -v NAME STATE VERSION * Ubuntu-22.04 Stopped 2
- バージョン変更
>wsl --set-version <Distribution Name> <1 or 2>
>wsl -l -o インストールできる有効なディストリビューションの一覧を次に示します。 'wsl --install -d <Distro>' を使用してインストールします。 NAME FRIENDLY NAME Ubuntu Ubuntu Debian Debian GNU/Linux kali-linux Kali Linux Rolling Ubuntu-18.04 Ubuntu 18.04 LTS Ubuntu-20.04 Ubuntu 20.04 LTS Ubuntu-22.04 Ubuntu 22.04 LTS OracleLinux_7_9 Oracle Linux 7.9 OracleLinux_8_7 Oracle Linux 8.7 OracleLinux_9_1 Oracle Linux 9.1 openSUSE-Leap-15.5 openSUSE Leap 15.5 SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4 SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5 openSUSE-Tumbleweed openSUSE Tumbleweed
- インストール
>wsl --install -d <Distribution Name>
- 規定のディストリビューションの変更
>wsl --set-default <Distribution Name>
- 指定ディストリビューションの実行(起動)
>wsl --distribution <Distribution Name> --user <User Name>
- 全てシャットダウン
>wsl --shutdown
参考
その他にもコマンドがあるので、ここを確認したら良いことあると思う
【備忘録】WSL2の導入
環境
- Windows10
参考
下記リンクを参考にした。
事前確認
次の要件を満たしているか確認。
Windows10 ビルド確認
Windowsメニュー>設定>システム>詳細情報

OSビルドが要件を満たしていないので、Windowsアップデートする必要がある。
でもWindowsアプデなんてサポート終了している今できるのか?
と思ったけど、「Windows Update」ページで「ダウンロードする」みたいなのがあったので、それをクリックしたら2,3時間かかったけどアップデートできた!
(残念ながらスクショは取れなかったごめん)
アプデ後がこれ

18917 以降になっていることを確認
Windows Insider Program の確認
なんだそれ?と調べたらこれが出てきた
富士通Q&A - Windows Insider Programについて教えてください。 - FMVサポート : 富士通パソコン
「開発中の機能など、一般提供前のWindowsを無料で試すことができるプログラム」のことらしい。
ほーん。
まあ確認していきましょう。
Windowsメニュー>設定>更新とセキュリティ>Windows Insider Program

なんかこんな感じのが出た。
「開始する」をクリックしてみる。

「登録」をクリック
出てくる文言を同意、新規登録を押したらなんかできた。

これで終わりだと思ったら違う?

アカウントを選んだらいい?
ってしたら同じ工程が出てきたぞ。
アカウント二つあるからアレだったのかな?
読み込み終わったらまた再起動。
起動後なんか出来てる気がするのでOK!
WSL の確認
C:\WINDOWS\system32>wsl -l Linux 用 Windows サブシステム ディストリビューション: Legacy (既定) C:\WINDOWS\system32>wsl -l -v NAME STATE VERSION * Legacy Stopped 1
WSLのバージョンが「1」であることを一応確認。
WSL2の導入
インストール時、ディストリビューションを指定しなきゃいけないらしい。
指定できるですディストリビューションは、「wsl -l -o」で確認できる。

Ubuntu22.04 をインストールしようと思うので、下記コマンドを実行
>wsl --install -d Ubuntu-22.04 インストール中: Ubuntu 22.04 LTS Ubuntu 22.04 LTS はインストールされました。 Ubuntu 22.04 LTS を起動しています...
インストール出来たら、Ubuntuのウィンドウが出てくるので、そこで「ユーザー名とパスワード」を新規設定したら完了!
WSL の確認
VERSION が「2」になってたら終わり!
なんだけど……
C:\WINDOWS\system32>wsl -l -v NAME STATE VERSION * Legacy Stopped 1 Ubuntu-22.04 Running 1
あれ……
変わってないね……
C:\WINDOWS\system32>wsl --set-version Ubuntu-22.04 2 変換中です。この処理には数分かかることがあります... WSL 2 との主な違いについては、https://aka.ms/wsl2 を参照してください Windows の仮想マシン プラットフォーム機能を有効にして、BIOS で仮想化が有効になっていることを確認してください。 詳細については、https://aka.ms/wsl2-install を参照してください
WSL2 への返還をしようとしたらエラーが出た
仮想化を有効にしなきゃいけないらしい
BIOSを見てみたけどそんな項目見当たらなかった……
無理なのか~!?
って思ったら、参考記事にこれがあった
PowerShellで以下コマンドを実行
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
上のコマンドがWSLの有効化
下のコマンドが仮想マシンプラットフォームの有効化
らしい
上記実行後、PC再起動する
PCが起動したらコマンドプロンプトで下記実行
>wsl --set-version Ubuntu-22.04 2
そして確認
>wsl -l -v NAME STATE VERSION * Ubuntu-22.04 Stopped 2
WSL2 に変わってる!
まとめ
記事はちゃんと読もう
ちゃんとその通りにしてみよう
を胸に刻みました
【備忘録】Apache2 デフォルトページを無効化したい
はじめに
/etc/httpd 形式じゃないことで躓いたので備忘録として残します。
環境
- ViutualBox
- Vagrant
- Ubuntu22.04
- Apache2.4
設定ファイルの置き場所は以下とします。
/etc/apache2
デフォルトページの無効化
結論から言うと「welcome.conf」は存在しない。
そのため、別の方法を模索する必要がある。
僕は、以下二点を実行することにした。
- 「index.html」があるっぽいので削除する
- 「apache2.conf」にデフォルトページに関する記述を変更/追加する
index.html の削除
そのまま削除してもいいけど別ファイルに名前を変えようと思う。
vagrant@vagrant:~$ ls -al /var/www/html/index.html -rw-r--r-- 1 root root 10671 Sep 12 00:05 /var/www/html/index.html vagrant@vagrant:~$ sudo mv /var/www/html/index.html /var/www/html/index.html.org vagrant@vagrant:~$ ls -al /var/www/html/index.html ls: cannot access '/var/www/html/index.html': No such file or directory
変更前

変更後

これはよろしくないのでconfファイルを変更する必要がある。
apache2.conf の変更
まずバックアップを取る。
vagrant@vagrant:~$ sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.o rg vagrant@vagrant:~$ sudo diff /etc/apache2/apache2.conf /etc/apache2/apache2.conf .org vagrant@vagrant:~$ sudo ls -al /etc/apache2/apache2.conf* -rw-r--r-- 1 root root 7224 May 4 05:02 /etc/apache2/apache2.conf -rw-r--r-- 1 root root 7224 Sep 15 06:22 /etc/apache2/apache2.conf.org
そして編集。
vagrant@vagrant:~$ sudo vim /etc/apache2/apache2.conf
Directory /var/www/
上記内の記述を変更する
変更前:Options Indexes FollowSymLinks
変更後:Options FollowSymLinks
vagrant@vagrant:~$ sudo diff /etc/apache2/apache2.conf /etc/apache2/apache2.conf.org 171c171 < Options FollowSymLinks --- > Options Indexes FollowSymLinks
apache2 を再起動する。
vagrant@vagrant:~$ sudo systemctl restart apache2
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-09-15 06:36:20 JST; 5s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1922 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1927 (apache2)
Tasks: 6 (limit: 2233)
Memory: 33.4M
CPU: 161ms
CGroup: /system.slice/apache2.service
├─1927 /usr/sbin/apache2 -k start
├─1928 /usr/sbin/apache2 -k start
├─1929 /usr/sbin/apache2 -k start
├─1930 /usr/sbin/apache2 -k start
├─1931 /usr/sbin/apache2 -k start
└─1932 /usr/sbin/apache2 -k start
Sep 15 06:36:20 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 15 06:36:20 vagrant apachectl[1925]: AH00558: apache2: Could not reliably determine the>
Sep 15 06:36:20 vagrant systemd[1]: Started The Apache HTTP Server.
- 変更後

これでデフォルトページが見れなくなった!
最後に
同じApache2.4 でも環境ごとに設定ファイルの置き場所やルールが違うことを改めて実感しました。
もっと意識していこうと思います。
【備忘録】Ubuntu22.04 で WordPress導入
はじめに
WordPress導入して、サイト作りたい。 なんか自分が形にしたものを集約させたい。 そのためにはLAMP環境が必要なので、環境を用意します。
前提
以下サイトを確認したところ、WordPress導入するためには、以下条件クリアしなければならないらしい。
インストールの前に – サポートフォーラム – WordPress.org 日本語
以下引用
サーバー側の要件 PHP 7.3 以上 MySQL 5.6 以上または MariaDB 10.1 以上
これに気を付けつつ、下記記事を参考に環境作り行きます。
Ubuntu 22.04 LSTにLAMP環境を構築しました! | ある退職者のライフスタイル
環境
- VirtualBox
- Vagrant
- Ubuntu22.04
- Apache2.4
- PHP8.1
- MySQL8.0
- WordPress6.3.1
Apacheインストール
なんか入ってなさそうだったので、 下記コマンドでインストール
$sudo apt install apache2
インストール出来ているかの確認は「dpkg -l」でするらしい。
vagrant@vagrant:~$ dpkg -l | grep "apache2" ii apache2 2.4.52-1ubuntu4.6 amd64 A pache HTTP Server ii apache2-bin 2.4.52-1ubuntu4.6 amd64 A pache HTTP Server (modules and other binary files) ii apache2-data 2.4.52-1ubuntu4.6 all A pache HTTP Server (common files) ii apache2-utils 2.4.52-1ubuntu4.6 amd64 A pache HTTP Server (utility programs for web servers)
なんかいそうなのでとりあえずOK。
ちゃんと動作確認もしようね。
ということでapache起動します。
vagrant@vagrant:~$ systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-09-11 15:05:09 UTC; 8min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 2172 (apache2)
Tasks: 55 (limit: 2233)
Memory: 5.2M
CPU: 101ms
CGroup: /system.slice/apache2.service
├─2172 /usr/sbin/apache2 -k start
├─2173 /usr/sbin/apache2 -k start
└─2174 /usr/sbin/apache2 -k start
Sep 11 15:05:09 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 11 15:05:09 vagrant apachectl[2171]: AH00558: apache2: Could not reliably determine the ser>
Sep 11 15:05:09 vagrant systemd[1]: Started The Apache HTTP Server.
と思ったけどもう起動してた~。
じゃあenableはどう?
vagrant@vagrant:~$ systemctl is-enabled apache2 enabled
既に enabled 済みだと……
いけいけ ubuntu 強い……
動作確認もしましょうね。

マシンのIPを直打ちして apache のページが見れることが確認できたね。
apache のバージョンはこれで確認できるらしい
vagrant@vagrant:~$ apache2ctl -v Server version: Apache/2.4.52 (Ubuntu) Server built: 2023-05-03T20:02:51
SSL対応
記事でSSL対応もしちゃってるので、僕もそうしようと思います。
SSLの設定が書かれているファイルを確認
vagrant@vagrant:~$ ls -al /etc/apache2/sites-available/ total 20 drwxr-xr-x 2 root root 4096 Sep 11 15:05 . drwxr-xr-x 8 root root 4096 Sep 11 15:05 .. -rw-r--r-- 1 root root 1332 May 3 20:02 000-default.conf -rw-r--r-- 1 root root 6338 May 3 20:02 default-ssl.conf
default-ssl.conf が対象みたい。
ここの中身を見てみよう。
less /etc/apache2/sites-available/default-ssl.conf
コメントアウトされてない「SSLCertificate」はこの二行だね
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
なんかこれがSSL証明書っぽそう。
一応指定場所にファイルがあるか確認しておこう。
vagrant@vagrant:~$ ls -l /etc/ssl/certs/ssl-cert-snakeoil.pem -rw-r--r-- 1 root root 1082 Sep 11 15:05 /etc/ssl/certs/ssl-cert-snakeoil.pem vagrant@vagrant:~$ ls -l /etc/ssl/private/ssl-cert-snakeoil.key ls: cannot access '/etc/ssl/private/ssl-cert-snakeoil.key': Permission denied vagrant@vagrant:~$ sudo ls -l /etc/ssl/private/ssl-cert-snakeoil.key -rw-r----- 1 root ssl-cert 1704 Sep 11 15:05 /etc/ssl/private/ssl-cert-snakeoil.key
鍵ファイルは sudo を付けて見にいこう。
(sudo付けないでコマンド叩いたら怒られた)
参考記事にはこう書いてあった。
Apache Webサーバーをインストールした段階でサンプルのSSL証明書が自動的に作成され、利用可能になっています。 サンプルの証明書の秘密鍵と公開鍵のファイル所在も、/etc/apache2/sites-available/default-ssl.confのファイルの中で指定されていて、変更する必要がありません。
そうなんだ。
証明書の存在が確認できたら、
次はApache側でSSLのモジュールとデフォルトのSSLを有効化していくみたい。
vagrant@vagrant:~$ sudo a2enmod ssl Considering dependency setenvif for ssl: Module setenvif already enabled Considering dependency mime for ssl: Module mime already enabled Considering dependency socache_shmcb for ssl: Enabling module socache_shmcb. Enabling module ssl. See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certi ficates. To activate the new configuration, you need to run: systemctl restart apache2
なんかいけたっぽい。
そんで、一番下の apache2 再起動をするみたい。
vagrant@vagrant:~$ sudo systemctl restart apache2
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-09-11 15:32:32 UTC; 6s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 2625 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 2629 (apache2)
Tasks: 55 (limit: 2233)
Memory: 6.1M
CPU: 53ms
CGroup: /system.slice/apache2.service
├─2629 /usr/sbin/apache2 -k start
├─2630 /usr/sbin/apache2 -k start
└─2631 /usr/sbin/apache2 -k start
Sep 11 15:32:32 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 11 15:32:32 vagrant apachectl[2628]: AH00558: apache2: Could not reliably determine the server'>
Sep 11 15:32:32 vagrant systemd[1]: Started The Apache HTTP Server.
sudo 忘れがちになっちゃう……
みんなも気をつけて……
次はデフォルトSSLを有効化させるのかな。
vagrant@vagrant:~$ sudo a2ensite default-ssl
Enabling site default-ssl.
To activate the new configuration, you need to run:
systemctl reload apache2
vagrant@vagrant:~$ sudo systemctl reload apache2
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-09-11 15:32:32 UTC; 2min 41s ago
なんかイケてそうなのでヨシ!
開いてるポートの確認
vagrant@vagrant:~$ nmap localhost Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-11 15:38 UTC Nmap scan report for localhost (127.0.0.1) Host is up (0.00018s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https
443 がいるのでヨシ!
web上はこんな感じ

記事ではこれでOKと書いてあるので、OKとします。
Apache はこれでおしまい!
PHPインストール
which で調べたけど php 入ってなさそうなのでインストールします。
WordPressの要件である下記以上のものを入れる。
PHP 7.3 以上
普通にインストールしてみたら、PHP8.1 が入りそうなので、このまま行こうと思う。
叩くコマンドはこれ
$sudo apt install php php-mbstring php-pear libapache2-mod-php php-mysql php-fpm php-xmlrpc php-soap php-intl
一応、バージョン確認
vagrant@vagrant:~$ php -v
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies
php.ini の設定
とりあえず、php.ini のバックアップを取る
vagrant@vagrant:~$ sudo cp /etc/php/8.1/apache2/php.ini /etc/php/8.1/apache2/php.ini.org vagrant@vagrant:~$ sudo diff /etc/php/8.1/apache2/php.ini /etc/php/8.1/apache2/php.ini.org vagrant@vagrant:~$ sudo ls -al /etc/php/8.1/apache2/ total 156 drwxr-xr-x 3 root root 4096 Sep 12 20:38 . drwxr-xr-x 6 root root 4096 Sep 11 15:45 .. drwxr-xr-x 2 root root 4096 Sep 11 15:45 conf.d -rw-r--r-- 1 root root 72928 Aug 18 11:41 php.ini -rw-r--r-- 1 root root 72928 Sep 12 20:38 php.ini.org
次にファイル編集
vagrant@vagrant:~$ sudo vi /etc/php/8.1/apache2/php.ini vagrant@vagrant:~$ sudo diff /etc/php/8.1/apache2/php.ini /etc/php/8.1/apache2/php.ini.org 698c698 < post_max_size = 8192M --- > post_max_size = 8M 850c850 < upload_max_filesize = 8192M --- > upload_max_filesize = 2M 968c968 < date.timezone = "Asia/Tokyo" --- > ;date.timezone = 1634c1634 < mbstring.language = Japanese --- > ;mbstring.language = Japanese 1641c1641 < mbstring.internal_encoding = UTF-8 --- > ;mbstring.internal_encoding = 1649c1649 < mbstring.http_input = UTF-8 --- > ;mbstring.http_input = 1659c1659 < mbstring.http_output = pass --- > ;mbstring.http_output = 1667c1667 < mbstring.encoding_translation = On --- > ;mbstring.encoding_translation = Off 1672c1672 < mbstring.detect_order = auto --- > ;mbstring.detect_order = auto 1677c1677 < mbstring.substitute_character = none --- > ;mbstring.substitute_character = none vagrant@vagrant:~$
fpm の www.conf の設定
まずバックアップを取る
vagrant@vagrant:~$ sudo cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/www.conf.org vagrant@vagrant:~$ sudo diff /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/www.conf.org vagrant@vagrant:~$ ls -al /etc/php/8.1/fpm/pool.d/ total 56 drwxr-xr-x 2 root root 4096 Sep 12 20:50 . drwxr-xr-x 4 root root 4096 Sep 11 15:45 .. -rw-r--r-- 1 root root 20876 Aug 18 11:41 www.conf -rw-r--r-- 1 root root 20876 Sep 12 20:50 www.conf.org
次にファイル編集
vagrant@vagrant:~$ sudo vi /etc/php/8.1/fpm/pool.d/www.conf vagrant@vagrant:~$ sudo diff /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/www.conf.org 50c50 < listen.mode = 0660 --- > ;listen.mode = 0660 116c116 < pm.max_children = 25 --- > pm.max_children = 5 121c121 < pm.start_servers = 10 --- > pm.start_servers = 2 126c126 < pm.min_spare_servers = 10 --- > pm.min_spare_servers = 1 131c131 < pm.max_spare_servers = 20 --- > pm.max_spare_servers = 3 148c148 < pm.max_requests = 500 --- > ;pm.max_requests = 500 vagrant@vagrant:~$
PHP動作確認
/var/www/html/phpinfo.php を作成する。
vagrant@vagrant:~$ sudo vi /var/www/html/phpinfo.php vagrant@vagrant:~$ sudo cat /var/www/html/phpinfo.php <?php phpinfo(); ?> vagrant@vagrant:~$
OS起動時にphp-fpmが起動するように設定されていることを確認
vagrant@vagrant:~$ systemctl list-unit-files --type=service | grep "php" php8.1-fpm.service enabled enabled phpsessionclean.service static - vagrant@vagrant:~$
「enabled」になっているから良さそう
起動済みになっているが、一応再起動しておこう
vagrant@vagrant:~$ systemctl status php8.1-fpm
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-09-12 20:36:07 UTC; 24min ago
Docs: man:php-fpm8.1(8)
Main PID: 680 (php-fpm8.1)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 2233)
Memory: 26.9M
CPU: 641ms
CGroup: /system.slice/php8.1-fpm.service
├─680 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" ">
├─816 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
└─817 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
Sep 12 20:36:04 vagrant systemd[1]: Starting The PHP 8.1 FastCGI Process Manager...
Sep 12 20:36:07 vagrant systemd[1]: Started The PHP 8.1 FastCGI Process Manager.
vagrant@vagrant:~$ sudo systemctl restart php8.1-fpm
vagrant@vagrant:~$ systemctl status php8.1-fpm
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-09-12 21:01:08 UTC; 2s ago
Docs: man:php-fpm8.1(8)
Process: 1877 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.>
Main PID: 1863 (php-fpm8.1)
Status: "Ready to handle connections"
Tasks: 11 (limit: 2233)
Memory: 13.2M
CPU: 178ms
CGroup: /system.slice/php8.1-fpm.service
├─1863 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" >
├─1867 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1868 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1869 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1870 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1871 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1872 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1873 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1874 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
├─1875 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
└─1876 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
Sep 12 21:01:08 vagrant systemd[1]: Starting The PHP 8.1 FastCGI Process Manager...
Sep 12 21:01:08 vagrant systemd[1]: Started The PHP 8.1 FastCGI Process Manager.
Apache も再起動しておこう
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-09-12 20:36:06 UTC; 26min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 798 (apache2)
Tasks: 6 (limit: 2233)
Memory: 20.8M
CPU: 652ms
CGroup: /system.slice/apache2.service
├─798 /usr/sbin/apache2 -k start
├─823 /usr/sbin/apache2 -k start
├─824 /usr/sbin/apache2 -k start
├─825 /usr/sbin/apache2 -k start
├─826 /usr/sbin/apache2 -k start
└─827 /usr/sbin/apache2 -k start
Sep 12 20:36:04 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 12 20:36:06 vagrant apachectl[757]: AH00558: apache2: Could not reliably determine the server's fully qu>
Sep 12 20:36:06 vagrant systemd[1]: Started The Apache HTTP Server.
vagrant@vagrant:~$ sudo systemctl restart apache2
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-09-12 21:02:55 UTC; 1s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1901 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1905 (apache2)
Tasks: 6 (limit: 2233)
Memory: 13.1M
CPU: 181ms
CGroup: /system.slice/apache2.service
├─1905 /usr/sbin/apache2 -k start
├─1906 /usr/sbin/apache2 -k start
├─1907 /usr/sbin/apache2 -k start
├─1908 /usr/sbin/apache2 -k start
├─1909 /usr/sbin/apache2 -k start
└─1910 /usr/sbin/apache2 -k start
Sep 12 21:02:55 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 12 21:02:55 vagrant apachectl[1904]: AH00558: apache2: Could not reliably determine the server's fully q>
Sep 12 21:02:55 vagrant systemd[1]: Started The Apache HTTP Server.
ブラウザから下記のような表示が見えたらOK

phpinfo.php は消しておこう
vagrant@vagrant:~$ cd /var/www/html/ vagrant@vagrant:/var/www/html$ sudo rm phpinfo.php vagrant@vagrant:/var/www/html$ ls -l total 12 -rw-r--r-- 1 root root 10671 Sep 11 15:05 index.html
MySQLのインストール
一応、MySQLが入ってないことを確認
vagrant@vagrant:~$ sudo dpkg -l | grep mysql ii php-mysql 2:8.1+92ubuntu1 all MySQL modu le for PHP [default] ii php8.1-mysql 8.1.2-1ubuntu2.14 amd64 MySQL modu le for PHP
mysql-server とかいないね。
というわけでインストールしよう。
これを満たすものになるように。
vagrant@vagrant:~$ sudo apt install mysql-client mysql-server Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl libmecab2 libprotobuf-lite23 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0 Suggested packages: libipc-sharedcache-perl mailx tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl libmecab2 libprotobuf-lite23 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 0 upgraded, 19 newly installed, 0 to remove and 116 not upgraded. Need to get 29.2 MB of archives. After this operation, 242 MB of additional disk space will be used. Do you want to continue? [Y/n]
mysql-client-8.0 とか書いてそうだからいけそう。
このまま yes でインストールしちゃいましょ。
インストール完了したら確認
vagrant@vagrant:~$ sudo dpkg -l | grep mysql ii mysql-client 8.0.34-0ubuntu0.22.04.1 all MySQL data base client (metapackage depending on the latest version) ii mysql-client-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL data base client binaries ii mysql-client-core-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL data base core client binaries ii mysql-common 5.8+1.0.8 all MySQL data base common files, e.g. /etc/mysql/my.cnf ii mysql-server 8.0.34-0ubuntu0.22.04.1 all MySQL data base server (metapackage depending on the latest version) ii mysql-server-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL data base server binaries and system database setup ii mysql-server-core-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL data base server binaries ii php-mysql 2:8.1+92ubuntu1 all MySQL modu le for PHP [default] ii php8.1-mysql 8.1.2-1ubuntu2.14 amd64 MySQL modu le for PHP vagrant@vagrant:~$
mysql が入ったことは分かったからOK!
mysql が起動しているか確認
vagrant@vagrant:~$ systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-09-14 08:11:42 UTC; 3min 36s ago
Process: 2631 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 2639 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 2233)
Memory: 365.2M
CPU: 7.217s
CGroup: /system.slice/mysql.service
└─2639 /usr/sbin/mysqld
Sep 14 08:11:39 vagrant systemd[1]: Starting MySQL Community Server...
Sep 14 08:11:42 vagrant systemd[1]: Started MySQL Community Server.
起動しているだと……!?
優秀ですね。
enable 設定も確認しとこっか
vagrant@vagrant:~$ systemctl is-enabled mysql enabled
enable にもなってる……
じゃああとは mysql の設定ですね。
my.conf 設定
上記記事も参考にします。
では、my.conf を作ります。
$sudo vim /etc/my.conf
ファイル内に以下をぶっこみます。
vagrant@vagrant:~$ sudo cat /etc/my.conf aracter_set_server = utf8mb4 # 文字コード collation_server = utf8mb4_ja_0900_as_cs # 照合順序 # timezone default-time-zone = SYSTEM log_timestamps = SYSTEM # Error Log log-error = /var/log/mysql/mysql-error.log # Slow Query Log slow_query_log = 1 slow_query_log_file = /var/log/mysql/mysql-slow.log long_query_time = 5.0 log_queries_not_using_indexes = 0 # General Log general_log = 1 general_log_file = /var/log/mysql/mysql-query.log [mysql] default-character-set = utf8mb4 [client] default-character-set = utf8mb4
一応ログあたりが現状ないことを確認。
vagrant@vagrant:~$ sudo ls -l /var/log/mysql/mysql-error.log ls: cannot access '/var/log/mysql/mysql-error.log': No such file or directory vagrant@vagrant:~$ sudo ls -l /var/log/mysql/mysql-slow.log ls: cannot access '/var/log/mysql/mysql-slow.log': No such file or directory vagrant@vagrant:~$ sudo ls -l /var/log/mysql/mysql-query.log ls: cannot access '/var/log/mysql/mysql-query.log': No such file or directory vagrant@vagrant:~$ sudo ls -l /var/log/mysql/ total 8 -rw-r----- 1 mysql adm 4288 Sep 14 08:11 error.log
よし、再起動しましょう。
vagrant@vagrant:~$ sudo systemctl restart mysql
vagrant@vagrant:~$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-09-14 08:25:26 UTC; 5s ago
Process: 2885 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 2894 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 2233)
Memory: 365.1M
CPU: 1.805s
CGroup: /system.slice/mysql.service
└─2894 /usr/sbin/mysqld
Sep 14 08:25:24 vagrant systemd[1]: Starting MySQL Community Server...
Sep 14 08:25:26 vagrant systemd[1]: Started MySQL Community Server.
MySQL 初期設定
初期設定前にパスワードがどうなってるか確認しとこう。
vagrant@vagrant:~$ sudo less /var/log/mysql/error.log | grep "pass" 2023-09-14T08:11:11.352119Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
直訳すると「空のパスワードで設定したよ!」らしい。
以上を踏まえていってみよう。
vagrant@vagrant:~$ sudo mysql_secure_installation 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: [Enter] Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more informatio n. 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 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? (Press y|Y for Yes, any other key for No) : y Success. 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) : 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? (Press y|Y for Yes, any other key for No) : y Success. All done!
あ、パスワード設定スルーしてしまった
vagrant@vagrant:~$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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 内でパスワード変更できます。
mysql> USE mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'secret'; Query OK, 0 rows affected (0.00 sec)
今回は新パスワード「secret」にしました。
一回mysql から抜けて新パスワードでログインできるか確認してみます。
vagrant@vagrant:~$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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のコマンドラインで-pオプションを使わずにパスワードを指定する方法 - インフラエンジニアway - Powered by HEARTBEATS
上記記事を参考に .my.conf を作成しよう
sudo vim /root/.my.conf
以下内容をぶっこむ
vagrant@vagrant:~$ sudo cat /root/.my.conf [client] password="secret"
ログインしてみよう
vagrant@vagrant:~$ sudo mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu) Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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>
-p つけずに入れた!
これで複雑なパスワードにしても安心してログインできるね。
MySQLサーバーの確認
現在の状態確認
mysql> status -------------- mysql Ver 8.0.34-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu)) Connection id: 14 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 UNIX socket: /var/run/mysqld/mysqld.sock Binary data as: Hexadecimal Uptime: 42 min 56 sec Threads: 2 Questions: 152 Slow queries: 0 Opens: 277 Flush tables: 3 Open tables: 196 Queries per second avg: 0.059 --------------
MySQLサーバーに登録されているユーザー一覧のユーザー名とホスト名の確認。
mysql> select user, host from mysql.user
-> ;
+------------------+-----------+
| user | host |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)
セミコロン入れるの忘れちゃった。
気を付けよう。
データーベース一覧の確認。
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
うん、まあこんなもんでいいでしょう。
WordPress インストール
やっとたどりついた……
Ubuntu 22.04 LTS に WordPress 6.2 をインストール - Qiita
上記記事を参考にする。
まず、ドキュメントルートに移動。
vagrant@vagrant:~$ cd /var/www/html vagrant@vagrant:/var/www/html$ pwd /var/www/html
最新版WordPressをダウンロードする
vagrant@vagrant:/var/www/html$ sudo wget https://ja.wordpress.org/latest-ja.tar.gz --2023-09-14 18:19:38-- https://ja.wordpress.org/latest-ja.tar.gz Resolving ja.wordpress.org (ja.wordpress.org)... 198.143.164.253 Connecting to ja.wordpress.org (ja.wordpress.org)|198.143.164.253|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 24293525 (23M) [application/octet-stream] Saving to: ‘latest-ja.tar.gz’ latest-ja.tar.gz 100%[=========================================>] 23.17M 1.55MB/s in 26s 2023-09-14 18:20:05 (922 KB/s) - ‘latest-ja.tar.gz’ saved [24293525/24293525] vagrant@vagrant:/var/www/html$ ls -l total 23740 -rw-r--r-- 1 root root 10671 Sep 12 00:05 index.html -rw-r--r-- 1 root root 24293525 Sep 4 14:00 latest-ja.tar.gz
解凍しよう。
vagrant@vagrant:/var/www/html$ sudo tar xvf latest-ja.tar.gz
WordPress用データベース作成
mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8; Query OK, 1 row affected, 1 warning (0.01 sec) mysql> show DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | wordpress | +--------------------+ 5 rows in set (0.00 sec)
ユーザーも作ろう
mysql> use wordpress; Database changed mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '[password]'; Query OK, 0 rows affected (0.03 sec) mysql> SELECT user,host FROM mysql.user; +------------------+-----------+ | user | host | +------------------+-----------+ | debian-sys-maint | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | | wordpress | localhost | +------------------+-----------+ 6 rows in set (0.00 sec) mysql> GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
FLUSH PRIVILEGES; ってなんぞやと思い調べた。
MySQLのFLUSH PRIVILEGESが必要なケース | my opinion is my own
とりあえずキャッシュをリフレッシュするやつって感じ? 削除系のクエリ(でいいの?)を実行したときは必ず必要見たい。
CUIはおしまい。
WordPress初期設定
上記アクセスすると、こんな画面が出てくる

始めるボタン押す。

データベースに設定した通りに記入

CUI 終わったと思ったけどそんなことなかった。
上記php の内容をぶっこむ。
vagrant@vagrant:~$ sudo vim /var/www/html/wordpress/wp-config.php
そんでインストールを押す。

お、進めた。
なんかよしなに名前を付けよう。
それでインストールを押す。

やった!できた!
長い道のりでした。
最後に
今回は下記インストールしました。 - 環境: Ubuntu22.04 - Apache2.4 - PHP8.1 - MySQL8.0 - WordPress6.3.1
3日くらいかかってしまいました。
でもこれを一度にするのは慣れてないと無理ですね。
備忘録も小分けにしたらよかったなと思いました。
誤字脱字・表記揺れは今回は気にしないでいただけると有難いです……
確認は無理だわこれ……
今後の反省、改善点とします。
ここまで読んでくださりありがとうございました。
【備忘録】API使わずに自動投稿がしたい(導入編)
開発環境
- Vagrant
- VirtualBox
- Ubuntu22.04
- Python3.10
目標
目標は 寄り添い型「タイッツー」で自動投稿する こと
しかし、まだAPI提供が始まっていないため、「APIなし」で出来ないか模索しようと思い、今回の環境を作りました。
やったこと
- Ubuntu22.04 の box 追加
- マシン起動
- pythonあるか確認
- pip インストール
- selenium インストール
- google-chrome インストール
- chrome のドライバーインストール
1. ubuntu22.04のbox追加
Vagrant box bento/ubuntu-22.04 - Vagrant Cloud
上記サイトからなんか良さそうなboxを探す。
今回は「bento/ubuntu-22.04」を入れた。
最新(202304)はVirtualBox が無いので、バージョンを指定する必要がある。
僕はダウンロードURLを直接指定してやった。
$ vagrant box add bento/ubuntu-22.04 https://app.vagrantup.com/bento/boxes/ubuntu-22.04/versions/202303.13.0/providers/virtualbox.box
環境によってめちゃ時間がかかるので気長に待とう。
box追加が完了したら、一応追加されているか確認
$ vagrant box list bento/centos7_lamp (virtualbox, 0) bento/ubuntu-22.04 (virtualbox, 0) juniper/ffp-12.1X47-D15.4-packetmode (virtualbox, 0.5.0) rockylinux/9 (virtualbox, 2.0.0)
2. マシン起動
先ほど追加したboxで初期化
$ vagrant init bento/ubuntu-22.04
次にマシンを起動
$ vagrant up
最初は時間がかかるので、気長に待つ。
完了したら一応状態確認。
$ vagrant status Current machine states: default running (virtualbox)
「running」になってたらOK
SSHする。
$ vagrant ssh
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed Sep 6 05:41:16 AM UTC 2023
System load: 0.0 Processes: 148
Usage of /: 15.8% of 30.34GB Users logged in: 1
Memory usage: 19% IPv4 address for eth0: 10.0.2.15
Swap usage: 0% IPv4 address for eth1: 192.168.33.10
* Introducing Expanded Security Maintenance for Applications.
Receive updates to over 25,000 software packages with your
Ubuntu Pro subscription. Free for personal use.
https://ubuntu.com/pro
This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento
Last login: Wed Sep 6 04:32:05 2023 from 10.0.2.2
vagrant@vagrant:~$
とりあえず、アップデートしとこうか。
$sudo apt update
3. pythonあるか確認
デフォルトのpython のバージョンが何か確認
vagrant@vagrant:~$ python -V -bash: python: command not found vagrant@vagrant:~$ python3 -V Python 3.10.12
pyhton3.10 を入れたかったので、そのまま使わせていただこう。
4. pip インストール
pip は入ってないみたいなので、インストールする
$sudo apt install python3-pip
なんかリスタートする?みたいなGUIみたいなの出てきたが、一番上を僕は選んだ。
次にpip のバージョンを確認。
vagrant@vagrant:~$ pip -V pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10) vagrant@vagrant:~$ pip3 -V pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
(pipが入ってることも確認できたね)
pip も pip3 も使えるみたい?
python3 と同じくpip3 を使って行こうと思う。
5. selenium インストール
pip でインストールしたらOK
$pip3 install selenium
ちゃんとインストールできたか確認
$pip3 list . . . selenium 4.12.0
ありそうなのでOK
6. google-chrome インストール
上記記事を参考にした。
# リポジトリの追加 $ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' # 公開鍵の登録 $ sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - # パッケージリストの更新 $ sudo apt update # インストール $ sudo apt install google-chrome-stable # バージョン確認 $ google-chrome --version
ここのバージョン確認の数字はメモしておこう。
あとで使うので。
$ google-chrome --version Google Chrome 116.0.5845.179
7. chrome のドライバーインストール
さっき見たchromeのバージョンとドライバーのバージョンを併せるらしい。
$ pip install chromedriver-binary==116.0.5845.179
こうか?ってしたらエラーがでた。(以下エラー文)
$ pip3 install chromedriver-binary==116.0.5845.179 Defaulting to user installation because normal site-packages is not writeable ERROR: Could not find a version that satisfies the requirement chromedriver-binary==116.0.5845.179 (from versions: 2.29.1, 2.31.1, 2.3 3.1, 2.34.0, 2.35.0, 2.35.1, 2.36.0, 2.37.0, 2.38.0, 2.39.0, 2.40.1, 2.41.0, 2.42.0, 2.43.0, 2.44.0, 2.45.0, 2.46.0, 70.0.3538.16.0, 7 0.0.3538.67.0, 70.0.3538.97.0, 71.0.3578.30.0, 71.0.3578.33.0, 71.0.3578.80.0, 71.0.3578.137.0, 72.0.3626.7.0, 72.0.3626.69.0, 73.0.36 83.20.0, 73.0.3683.68.0, 74.0.3729.6.0, 75.0.3770.8.0, 75.0.3770.90.0, 75.0.3770.140.0, 76.0.3809.12.0, 76.0.3809.25.0, 76.0.3809.68.0 , 76.0.3809.126.0, 77.0.3865.10.0, 77.0.3865.40.0, 78.0.3904.11.0, 78.0.3904.70.0, 78.0.3904.105.0, 79.0.3945.16.0, 79.0.3945.36.0, 80 .0.3987.16.0, 80.0.3987.106.0, 81.0.4044.20.0, 81.0.4044.69.0, 81.0.4044.138.0, 83.0.4103.14.0, 83.0.4103.39.0, 84.0.4147.30.0, 85.0.4 183.38.0, 85.0.4183.83.0, 85.0.4183.87.0, 86.0.4240.22.0, 87.0.4280.20.0, 87.0.4280.87.0, 87.0.4280.88.0, 88.0.4324.27.0, 88.0.4324.27 .1, 88.0.4324.96.0, 89.0.4389.23.0, 90.0.4430.24.0, 91.0.4472.19.0, 91.0.4472.101.0, 92.0.4515.43.0, 92.0.4515.107.0, 93.0.4577.15.0, 93.0.4577.63.0, 94.0.4606.41.0, 94.0.4606.61.0, 94.0.4606.113.0, 95.0.4638.10.0, 95.0.4638.17.0, 95.0.4638.54.0, 95.0.4638.69.0, 96.0. 4664.18.0, 96.0.4664.35.0, 96.0.4664.45.0, 97.0.4692.20.0, 97.0.4692.36.0, 97.0.4692.71.0, 98.0.4758.48.0, 98.0.4758.80.0, 98.0.4758.1 02.0, 99.0.4844.17.0, 99.0.4844.35.0, 99.0.4844.51.0, 100.0.4896.20.0, 100.0.4896.60.0, 101.0.4951.15.0, 101.0.4951.41.0, 102.0.5005.2 7.0, 102.0.5005.61.0, 103.0.5060.24.0, 103.0.5060.53.0, 103.0.5060.134.0, 103.0.5060.134.1, 104.0.5112.20.0, 104.0.5112.29.0, 104.0.51 12.79.0, 105.0.5195.19.0, 105.0.5195.52.0, 106.0.5249.21.0, 106.0.5249.61.0, 107.0.5304.18.0, 107.0.5304.18.1, 107.0.5304.62.0, 108.0. 5359.22.0, 108.0.5359.71.0, 109.0.5414.25.0, 109.0.5414.74.0, 110.0.5481.30.0, 110.0.5481.77.0, 111.0.5563.19.0, 111.0.5563.41.0, 111. 0.5563.64.0, 112.0.5615.28.0, 112.0.5615.49.0, 113.0.5672.24.0, 113.0.5672.63.0, 114.0.5735.16.0, 114.0.5735.90.0, 115.0.5790.102.0, 1 15.0.5790.170.0, 116.0.5845.42.0, 116.0.5845.49.0, 116.0.5845.62.0, 116.0.5845.82.0, 116.0.5845.96.0, 117.0.5907.0.0, 117.0.5908.0.0, 117.0.5912.0.0, 117.0.5916.0.0, 117.0.5917.0.0, 117.0.5918.0.0, 117.0.5922.0.0, 117.0.5923.0.0, 117.0.5926.0.0, 117.0.5928.0.0, 117.0. 5930.0.0, 117.0.5931.0.0, 117.0.5933.0.0, 117.0.5935.0.0, 117.0.5937.0.0, 117.0.5938.2.0, 117.0.5938.4.0, 117.0.5938.11.0, 117.0.5938. 22.0, 117.0.5938.35.0, 118.0.5940.0.0, 118.0.5941.0.0, 118.0.5943.0.0, 118.0.5950.0.0, 118.0.5952.2.0, 118.0.5954.0.0, 118.0.5955.0.0, 118.0.5958.0.0, 118.0.5960.0.0, 118.0.5962.0.0, 118.0.5964.0.0, 118.0.5968.0.0, 118.0.5970.0.0, 118.0.5972.0.0, 118.0.5974.0.0, 118.0 .5976.0.0, 118.0.5978.0.0, 118.0.5980.0.0, 118.0.5982.0.0) ERROR: No matching distribution found for chromedriver-binary==116.0.5845.179
そのバージョンはないよ!ココの中から選んでね!だと推測。
で、一番近いバージョンを使うことにした。
$ pip3 install chromedriver-binary==116.0.5845.96.0 Defaulting to user installation because normal site-packages is not writeable Collecting chromedriver-binary==116.0.5845.96.0 Downloading chromedriver-binary-116.0.5845.96.0.tar.gz (5.6 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages: chromedriver-binary Building wheel for chromedriver-binary (setup.py) ... done Created wheel for chromedriver-binary: filename=chromedriver_binary-116.0.5845.96.0-py3-none-any.whl size=6710196 sha256=ce2e97cd080 539fcf070afb718fbef763e55d4c19eb18df49ebf04ff3d1c6edf Stored in directory: /home/vagrant/.cache/pip/wheels/24/04/b1/6a955258fb4d8de9b7b03440e7cc481a39d20e172adc6c5f02 Successfully built chromedriver-binary Installing collected packages: chromedriver-binary WARNING: The script chromedriver-path is installed in '/home/vagrant/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed chromedriver-binary-116.0.5845.96.0
なんかいけたみたい。
これでちゃんと動いてくれるかの確認をする。
適当なtest.py ファイルを作って下記コードをぶっこむ。
from selenium import webdriver
from selenium.webdriver import ChromeOptions
import chromedriver_binary
options = ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
# options.add_argument('--disable-gpu') # ページによって必要な場合がある模様
url = "https://zenn.dev/"
driver = webdriver.Chrome(options=options)
driver.get(url)
print(driver.title)
driver.quit()
そんで、実行する
$ python3 test.py Zenn|エンジニアのための情報共有コミュニティ
指定したURLの見出しかなんか引っ張ってこれてるから多分OKなんだと思う。
ここまで出来たら環境作り終わり!
最後に
数年前の間隔で「CentOS7」やら「Ubuntu16」やらで環境作ろうとして挫折しかけました。
少し離れただけでなんもわからんになるエンジニア世界。
分かっていたつもりでしたが身をもって体験しました。
相談に乗ってくれた旧友各位に感謝を表します。