在MAMP中使用Laravel设置PostgreSQL [英] setup PostgreSQL with Laravel in MAMP

查看:384
本文介绍了在MAMP中使用Laravel设置PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MAC上使用MAMP.由于默认情况下MySQL附带.但是现在我需要在我的项目之一中使用PostgreSQL.如何在Laravel项目的MAMP中设置postgreSQL?

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?

推荐答案

好吧,如果您打算通过MAMP附带的mySQL使用postgreSQL,则必须在位置机器上手动安装postgreSQL,才能找到OSX软件包此处

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,

如果您不想进行完整安装,我推荐此 Postgres应用,只需将摘录下载到您的应用中文件夹,然后在启动它时,端口号将显示在菜单栏中,如下所示:

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:

创建数据库:

  1. 转到上方菜单,单击打开psql"
  2. 在命令行中按如下方式创建数据库:CREATE DATABASE your_database_name;
  3. 应返回CREATE 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

提示退出postgreSQL CLI,请使用\q然后按ENTER

Tip to exit postgreSQL CLI use \q then ENTER

您现在需要将以下设置插入Laravels配置中:

You now need to plug these settings into Laravels configuration:

  1. 打开文件:%laravel_directory%/app/config/database.php
  2. 将数组中的'default' => 'mysql',替换为'default' => 'pgsql',
  3. 现在包含编辑'connections'数组之前的信息,如下所示:

  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',
    ),
)

  • 保存文件

  • save file

    您现在应该拥有一个可正常运行的数据库,Laravel可以与之通信.

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

    请注意,如果您使用的是 Postgres应用,则在数据库配置中不需要用户名或密码.

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

    这篇关于在MAMP中使用Laravel设置PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆