2021年01月10日

Windows 10にWSL2環境のUbuntu 20.04 LTSをインストールするメモ このエントリーをはてなブックマークに追加

ふと意味もなく冬休みにWindows10にUbuntuの環境でも作ってみるかということで作ってみた時のメモ。

WSL2の設定

Microsoftのページを元にWSL2の更新
Windows Subsystem for Linux (WSL) を Windows 10 にインストールする | Microsoft Docs
上記ページの手順に基づきUbuntu 20.04 LTSをインストール。基本的にこれだけでインストール完了。驚くほど何もしなくてええんやな。
さて動くのか試してみる
ryouchi@DESKTOP-3DLJ3DL:~$ uname -a
Linux DESKTOP-3DLJ3DL 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
ryouchi@DESKTOP-3DLJ3DL:~$ cat /etc/issue
Ubuntu 20.04.1 LTS \n \l
無事インストールできているっぽい。

ネットワークの設定

WSLなのでWindows環境下で動いているっぽいのだが、IPアドレスとかどうなってるんやろ?
ifconfigを実行したが
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
とのことだったので
ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt install net-tools
としてみた。その後
ryouchi@DESKTOP-3DLJ3DL:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.191.220 netmask 255.255.240.0 broadcast 192.168.191.255
inet6 fe80::215:5dff:fe87:ac40 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:87:ac:40 txqueuelen 1000 (Ethernet)
RX packets 253 bytes 222617 (222.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 106 bytes 7453 (7.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
で、仮想マシンのIPアドレスがわかった。外部に公開するものではないのでこれでええやろ。

ftpサーバをインストール

Windowsとのデータのやりとりのためにftpが繋がるかやってみたがftpサービスがインストールされていなかったのでインストールしてみる。
ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt install vsftpd

ryouchi@DESKTOP-3DLJ3DL:~$ sudo service vsftpd start
* Starting FTP server vsftpd /usr/sbin/vsftpd already running.

chkconfigの代わりにsysv-rc-confをインストール

どうやらchkconfigはないので代わりにsysv-rc-confをインストールするらしい。
ryouchi@DESKTOP-3DLJ3DL:~$ wget http://archive.ubuntu.com/ubuntu/pool/universe/s/sysv-rc-conf/sysv-rc-conf_0.99.orig.tar.gz
ryouchi@DESKTOP-3DLJ3DL:~$ tar zxvf sysv-rc-conf_0.99.orig.tar.gz
ryouchi@DESKTOP-3DLJ3DL:~$ cd sysv-rc-conf-0.99/
ryouchi@DESKTOP-3DLJ3DL:~$ sudo make install
ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt install libcurses-ui-perl libterm-readkey-perl libcurses-perl
ryouchi@DESKTOP-3DLJ3DL:~$ sudo sysv-rc-conf
なんとなく動いた。

apacheのインストール

ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt install apache2-bin
ryouchi@DESKTOP-3DLJ3DL:~$ sudo service apache2 start
Windowsから
bitsadmin /TRANSFER htmlget http://192.168.178.162/ c:\users\ryouchi\desktop\test.html
としてみると「Apache2 Ubuntu Default Page」がゲットできていたのでインストール完了。

phpのインストール

以下で紹介されている通りにインストールしてみたらすんなり動いた。
Ubuntu 20.04 LTS : Apache2 : PHP スクリプトを利用する : Server World
ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt install php7.4-cli
ryouchi@DESKTOP-3DLJ3DL:~$ php -v
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
ryouchi@DESKTOP-3DLJ3DL:~$ sudo apt -y install libapache2-mod-php php-common php-pear php-mbstring
ryouchi@DESKTOP-3DLJ3DL:~$ sudo a2enconf php7.4-cgi
ryouchi@DESKTOP-3DLJ3DL:~$ sudo vim /etc/php/7.4/apache2/php.ini
ryouchi@DESKTOP-3DLJ3DL:~$ sudo service apache2 restart
これでいろいろ遊べそうだな。
posted by りょーち | Comment(1) | 自分メモ
この記事へのコメント
コトタマ
Posted by 言霊 at 2023年06月09日 16:17
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント: