Skip to content

Instantly share code, notes, and snippets.

@jackvial
Last active November 10, 2022 21:25
Show Gist options
  • Save jackvial/52895ffb63e68f890a4f8c786c181202 to your computer and use it in GitHub Desktop.
Save jackvial/52895ffb63e68f890a4f8c786c181202 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

@erayerdin
Copy link

It's better readable with my fork. Please review it.

@patrickcurl
Copy link

Hey @jackvial found this googling laravel postgres packages on github just thought I'd say hey, not often I find someone I know high up in search results.

See: https://search.brave.com/search?q=site%3Agithub.com+postgres+views+laravel&source=web&tf=py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment