setup PostgreSQL with Laravel in MAMP

不问归期 提交于 2020-01-01 00:48:20

问题


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:


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:

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.



来源:https://stackoverflow.com/questions/18201623/setup-postgresql-with-laravel-in-mamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!