带有 Laravel Unix 套接字的 MAMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27365473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MAMP with Laravel Unix Socket
提问by user3732216
I'm working with MAMP on my local development server on my laravel application and I'm trying to figure out how I can safely setup my server so I don't have to use the following into the database connections mysql array because that should only be used when I'm on my development server. It works when I add the line into the mysql array however that isn't used if I was on a production server. Any ideas?
我正在我的 Laravel 应用程序的本地开发服务器上使用 MAMP,我试图弄清楚如何安全地设置我的服务器,这样我就不必在数据库连接 mysql 数组中使用以下内容,因为这应该只当我在我的开发服务器上时使用。当我将该行添加到 mysql 数组时它会起作用,但是如果我在生产服务器上则不会使用它。有任何想法吗?
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
.env.development.php
.env.development.php
<?php
return [
'DB_HOST' => '127.0.0.1',
'DB_USERNAME' => 'root',
'DB_PASSWORD' => '1234',
'DB_NAME' => 'mytable'
];
app/config/database.php
应用程序/配置/数据库.php
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
采纳答案by Hkan
Check the environment detectionpart in the bootstrap/start.php
. You should add your machine's name to the array that has local
key. (If you don't know your machine's name, run hostname
in terminal. If it's something stupid, Google how to change it. It's pretty simple.) Then copy and paste your database configurations to app/config/local/database.php
. Create the file if it doesn't exists.
检查 中的环境检测部分bootstrap/start.php
。您应该将您的机器名称添加到具有local
密钥的数组中。(如果您不知道您的机器名称,请hostname
在终端中运行。如果它很愚蠢,请谷歌如何更改它。非常简单。)然后将您的数据库配置复制并粘贴到app/config/local/database.php
. 如果文件不存在,则创建该文件。
回答by S. M. Ibrahim Lavlu
There is even simple solution. add this to ur .env file
甚至有简单的解决方案。将此添加到您的 .env 文件中
DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock
回答by Fausto Braz
On config/database.php
:
在config/database.php
:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'unix_socket' => env('UNIX_SOCKET'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
On .env
:
在.env
:
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mytable
DB_USERNAME=root
DB_PASSWORD=1234
UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
回答by HymanWalsh
Make sure MAMP preference is set to Apache port: 80, Nginx Port: 80, MySQL Port: 3306
确保 MAMP 首选项设置为 Apache 端口:80、Nginx 端口:80、MySQL 端口:3306
Here's what worked for me with Laravel 5.7:
以下是 Laravel 5.7 对我有用的内容:
go to config/database.php and find the line 54 below:
转到 config/database.php 并找到下面的第 54 行:
before: 'unix_socket' => env('DB_SOCKET', ''),
之前:'unix_socket' => env('DB_SOCKET', ''),
After: 'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
之后:'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
Save the file.
保存文件。
Then in terminal run: php artisan config:cache php artisan migrate
然后在终端运行: php artisan config:cache php artisan migrate
回答by Friendly Code
If none of the above solutions worked for you.....
如果以上解决方案都不适合您......
Try actually starting your webserver as this was the fix for me
尝试实际启动您的网络服务器,因为这对我来说是解决方案