0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2のubuntuにapacheとphpをインストールしてバージョン管理

Last updated at Posted at 2021-11-26

この記事は、zennに書いた WSL2のubuntuにapacheとphpをインストールしてバージョン管理 のコピーです。


さこつです。無事退職しました。

XAMPPのアップデートめんどくさい!でも自分のPC環境でphpのバージョン管理したい!!と試行錯誤した結果、
WSL2のubuntuにapacheとphpをインストールすることになったお話。

ubuntuのapacheならラクそう

こういう記事があった。ubuntu20.04.1 phpのバージョンを切り替える

そうだ、WSL2のubuntuにapacheを入れて管理しよう

1.上記をもとにphpをインストール

ただし、2021年11月27日時点でphp8.1をインストールするとapacheが503エラーで動かなくなるので注意。
7.3、7.4、8.0くらいにしとく。 → 動くようになりました(2021/12/20 追記)

その後、apacheインストール。

apacheのphpバージョン変更はこちら。https://mebee.info/2021/08/02/post-29391/

2.ドキュメントルート変更

ユーザーディレクトリ内にあったほうがテスト環境としては何かと便利である。
apache2.conf、000-default.conf(のコピー)、default-ssl.conf(のコピー)のドキュメントルートを、
/home/ユーザー名/wwwなどに変更する。

3.ssl設定

せっかくなのでhttpsでアクセスできるようにする。

default-ssl.conf(のコピー)

SSLCertificateFile	/etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

SSLCertificateFile	/etc/ssl/myssl.crt
SSLCertificateKeyFile /etc/ssl/myssl.key

とかに変更。

こちら XAMPP for WindowsでSSLを有効にする を参考に、
/etc/ssl/内でopenssl-san.cnfを作成、

openssl-san.cnf
$ openssl req \
    -newkey     rsa:4096 \
    -keyout     myssl.key \
    -x509 \
    -nodes \
    -out        myssl.crt \
    -subj       "/CN=localhost" \
    -reqexts    SAN \
    -extensions SAN \
    -config     openssl-san.cnf \
    -days       365000

などとした。

※daysが3650のままでは現状で証明書の期限が切れている。またWSL内なので//CNのバックスラッシュは1つで良い。

4.apache再起動

tarminal
sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
sudo a2ensite 000-default(のコピー).conf
sudo a2ensite default-ssl(のコピー).conf

のあと

tarminal
sudo service apache2 restart

5.OKだ

000.png

所感

ubuntuだとphpのバージョンアップも apt update でできてホントよい。

なお、ファイルとフォルダのパーミッションに注意。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?