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 1 year has passed since last update.

wsl2 + Ubuntu + LaravelにPostgreSQLを構築する方法

Last updated at Posted at 2023-05-28

各バージョン

OS:Windows10 x64
Ubuntu:20.04
PostgreSQL:12.15
Laravel:8.83.27

まず初めに

Laravel環境はできているものとします。

失敗

以下より、windows版のPostgreSQLをダウンロード
PostgreSQLのリンク
※実際に疎通できているかはA5m2でもCLIでもよいのでSQL接続できるか確認しておくとよい

すべて完了し、Laravelのmigrateを行う

php artisan migrate

エラー

Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432? (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')

いろいろ調べてみたが解決策見当たらず。少し考えて仮説を立てた

LaravelでDBに関する情報は設定し、「データベースの接続先は127.0.0.1にありますよ」と定義すると、Laravelはwsl2上に構築しているから、wsl2のローカルipを見に行ってる説。
もし、windowsのPostgreSQLにアクセスするには何らかの手段でwsl2から物理pc(windows)のローカルアドレス(127.0.0.1)に疎通させる、あるいは物理PCのグローバルIPを見る必要がありそうな気がしてきた。
※間違ってたら申し訳ありません。

ということで面倒なので、コマンドラインよりwsl2上にPostgreSQLを構築

sudo apt install postgresql postgresql-contrib

実行。

zombie@DESKTOP-JLU30CD:~/working/study_Laravel/myapp$ psql --version
psql (PostgreSQL) 12.15 (Ubuntu 12.15-0ubuntu0.20.04.1)

成功。

ぽすぐれのパスワード変更

sudo -u postgres psql
ALTER ROLE postgres WITH PASSWORD 'passwordを記入'

本題に戻って

php artisan migrate

実行。成功。

結果

自分で立てた仮説を信じたい。とりあえずできてよかった。

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?