Skip to content

Commit 82c7de2

Browse files
authored
Update baseline.md
1 parent 5d03a12 commit 82c7de2

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

  • content/learning-paths/servers-and-cloud-computing/ruby-on-rails

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The output should look like:
4545
This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**.
4646

4747
```console
48-
sudo -u postgres createuser --superuser gcpuser
48+
sudo -u postgres psql -c "CREATE USER gcpuser WITH SUPERUSER PASSWORD 'your_password';"
4949
```
5050
- `sudo -u postgres` → Runs the command as the `postgres` user (default PostgreSQL superuser).
5151
- `createuser --superuser gcpuser` → Creates a PostgreSQL role named `gcpuser` with full admin privileges.
@@ -55,6 +55,15 @@ sudo -u postgres createuser --superuser gcpuser
5555

5656
This role will be used by Rails to connect to the PostgreSQL database.
5757

58+
### Set Environment variables
59+
60+
Before you create your Rails app, set the following environment variables:
61+
62+
```console
63+
export PGUSER=gcpuser
64+
export PGPASSWORD=your_password
65+
export PGHOST=localhost
66+
```
5867
### Create a Rails App with PostgreSQL
5968
Creates a new Rails application configured to use PostgreSQL as its database.
6069

@@ -72,10 +81,10 @@ Check `config/database.yml` to ensure the `username` and `password` match your P
7281
{{% /notice %}}
7382

7483
### Verify and Update Database Configuration
75-
Open the Rails database configuration file:
84+
Open and modify your Rails database configuration file:
7685

7786
```console
78-
vi config/database.yml
87+
sudo vi config/database.yml
7988
```
8089
Find the `default`: and `development`: sections.
8190
Ensure the username matches the PostgreSQL user you created (gcpuser):
@@ -86,13 +95,40 @@ default: &default
8695
adapter: postgresql
8796
encoding: unicode
8897
username: gcpuser
89-
password:
98+
password: your_password
9099
host: localhost
91100
pool: 5
92101
93102
development:
94103
<<: *default
95104
```
105+
106+
### Change the Authentication Method
107+
Change the authentication method in the PostgreSQL configuration file `pg_hba.conf` from `ident` to `md5`.
108+
109+
Open your configuration file
110+
```console
111+
sudo vi /var/lib/pgsql/data/pg_hba.conf
112+
```
113+
Find lines that look like this:
114+
```output
115+
# IPv4 local connections:
116+
host all all 127.0.0.1/32 ident
117+
# IPv6 local connections:
118+
host all all ::1/128 ident
119+
```
120+
Change the method on these lines to look like:
121+
```output
122+
# IPv4 local connections:
123+
host all all 127.0.0.1/32 md5
124+
# IPv6 local connections:
125+
host all all ::1/128 md5
126+
```
127+
Save the file. Restart PostgreSQL:
128+
129+
```console
130+
sudo systemctl restart postgresql
131+
```
96132
### Create and Initialize the Database
97133
Initializes and creates the development and test databases for your Rails app using PostgreSQL.
98134

0 commit comments

Comments
 (0)