问题
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:
- go to menu above Click on Open psql
- In the command line create you database like so:
CREATE DATABASE your_database_name;
- should return
CREATE DATABASE
Tip to exit postgreSQL CLI use \q
then ENTER
You now need to plug these settings into Laravels configuration:
- open file: %laravel_directory%/app/config/database.php
- in the array replace
'default' => 'mysql',
with'default' => 'pgsql',
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
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