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?

Postgresサーバーを建てる。Ubuntuでやってます。

Posted at

AIでやると、自分好みじゃないモノが出るときがあるので、自分用にきちんとメモ。

Ubuntu24.04でやってます。

Posgresのインストール

パッケージ更新

sudo apt update

PostgreSQL インストール

sudo apt install -y postgresql postgresql-contrib

起動確認

sudo systemctl status postgresql

postgresユーザーに切り替えてパスワード設定

sudo -u postgres psql
postgres=# ALTER USER postgres PASSWORD 'your_strong_password';
postgres=# CREATE DATABASE mydb;
postgres=# \q;
sudo vi /etc/postgresql/*/main/pg_hba.conf

末尾にhost all all 0.0.0.0/0 md5を追加

/etc/postgresql/*/main/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             0.0.0.0/0               md5
sudo vi /etc/postgresql/*/main/postgresql.conf

listen_addressesを変更

/etc/postgresql/*/main/postgresql.conf
listen_addresses = '*'

設定を変更したので、postgresの再起動

sudo systemctl restart postgresql

Adminer インストール

AdminerはPHP製の軽量GUIクライアントです。
PhpMyAdminみたいなもんですね。

sudo apt install -y php-fpm php-pgsql
# Adminerダウンロード
sudo mkdir -p /var/www/adminer
cd /var/www/adminer
sudo wget https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php -O index.php
sudo chown -R www-data:www-data /var/www/adminer

AdminerのためのNginxの設定

sudo apt install -y nginx

sites-availableのファイルを追加することで有効化する

sudo vi /etc/nginx/sites-available/adminer
/etc/nginx/sites-available/adminer
server {
    listen 8080;
    server_name _;
    root /var/www/adminer;
    index index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;  # バージョン確認して調整
    }
}
# 有効化
sudo ln -s /etc/nginx/sites-available/adminer /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
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?