Skip to content

Instantly share code, notes, and snippets.

@erayerdin
Forked from jackvial/postgres-setup.md
Created March 5, 2020 00:01
Show Gist options
  • Save erayerdin/a08e88b17a970135309d3952b31b269b to your computer and use it in GitHub Desktop.
Save erayerdin/a08e88b17a970135309d3952b31b269b to your computer and use it in GitHub Desktop.
Laravel Postgres Setup

Postgres Setup

Step 1: Install PostgreSQL

Here are the installation steps on Ubuntu (this installation will also work on any Debian-based distribution):

  1. Open a terminal window.
  2. Issue the command sudo apt-get install postgresql.
  3. Type the sudo password necessary to give you admin rights and hit Enter.
  4. Allow apt to pick up any necessary dependencies.
  5. 
 Once the installation is complete, it's time to set this baby up.

*** On mac or windows its easier to install with windows I exposed port 5432 to 54320

Step 2: Change the default user password

Caution: If you don't follow this step, you will not be able to add databases and administer PostgreSQL, and the database will not be secure. Here's how to change the password for the default user. The user in question is postgres, and the password is changed like so:

  1. Open a terminal window.
  2. Issue the command sudo passwd postgres.
  3. Type (and confirm) that password to be used for this user.

The postgres user will be the only user on your system that can open the PostgreSQL prompt without defining a database, which means postgres is the only user who can administer PostgreSQL. To test this, change to the postgres user with the command su - postgres and then enter the command psql. You should now be at the Postgres prompt, which looks like: postgres=# All other users have to gain access to the prompt like so: psql DB_NAME where DB_NAME is the name of an existing database.

Step 3: Change the Postgres admin password

The administrator password must be set; otherwise, external applications will not be able to communicate with the databases. To change the admin password for Postgres, follow these steps:

  1. Open a terminal window.
  2. Change to the postgres user.
  3. Log in to the postgres prompt.
  4. Issue the command \password postgres.
  5. Enter (and verify) the new password.
  6. Exit the prompt with the command \q.

Postgres Cheatsheet

https://gist.github.com/Kartones/dd3ff5ec5ea238d4c546

Postgres terminal Client for connect from host machine to docker https://www.pgcli.com/

create your table using the cli

Install php pgsql driver

brew install php55-pdo-pgsql

for other php version, search with: brew search pgsql

Db connection .env

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54320
DB_DATABASE=yourdb
DB_USERNAME=postgres
DB_PASSWORD=password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment