setup PostgreSQL with Laravel in MAMP

前端 未结 1 1137
清酒与你
清酒与你 2021-02-06 19:18

I am using MAMP on my MAC. As it comes with MySQL by default. But now I need to use PostgreSQL in one of my project. How can I setup postgreSQL in MAMP for Laravel project?

1条回答
  •  臣服心动
    2021-02-06 19:41

    Ok if you are set on using postgreSQL over mySQL that comes with MAMP you have to manually install postgreSQL on you location machine the OSX packages can be found here,

    If you don't want to do a full install i recommend this Postgres App just download an extract to your applications folder then when you launch it the port number will be displayed in the menu bar like so:

    Postgres.app

    create a database:

    1. go to menu above Click on Open psql
    2. In the command line create you database like so: CREATE DATABASE your_database_name;
    3. should return CREATE DATABASE

    Tip to exit postgreSQL CLI use \q then ENTER

    You now need to plug these settings into Laravels configuration:

    1. open file: %laravel_directory%/app/config/database.php
    2. in the array replace 'default' => 'mysql', with 'default' => 'pgsql',
    3. now with the information from before edit the 'connections' array like so:

      'connections' => array(
          'pgsql' => array(
              'driver'   => 'pgsql',
              'host'     => 'localhost',
              'database' => 'your_database_name',
              'username' => '',
              'password' => '',
              'charset'  => 'utf8',
              'prefix'   => '',
              'schema'   => 'public',
          ),
      )
    4. save file

    You should now have a functioning database that Laravel can talk to.

    Note you do not need the username or password in database config if you are using the Postgres App.

    0 讨论(0)
提交回复
热议问题