使用 MAMP 在 OSX 上安装 Laravel 5.1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32504748/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:07:38  来源:igfitidea点击:

Installing Laravel 5.1 on OSX with MAMP

macoslaravelmamplaravel-5.1

提问by Marty Thomas

I tried to install Laravel 5.1 on OSX Yosemite with MAMP, and ran across a couple of road blocks. Specifically, I got the following error when trying to migrate the database.

我尝试使用 MAMP 在 OSX Yosemite 上安装 Laravel 5.1,但遇到了几个障碍。具体来说,我在尝试迁移数据库时遇到以下错误。

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

回答by Marty Thomas

1) Install Composer

1) 安装作曲家

If you don't yet have composer installed, you will need to do that. You can test weather you have composer installed by simply typing in the composercommand into mac's terminal. You should see a list of available commands if composer is installed.

如果你还没有安装 composer,你需要安装。您可以通过在composermac 的终端中输入命令来测试安装了 composer 的天气。如果安装了 composer,您应该会看到可用命令的列表。

Screen Shot 2015-08-17 at 1.34.05 PM.png

屏幕截图 2015-08-17 at 1.34.05 PM.png

If you don't yet have composer installed, you can see Getting Started with Composer

如果您还没有安装 composer,您可以查看Composer 入门

2) Install Laravel

2) 安装 Laravel

Laravel has good documentation in installing Laravel. I'll walk through exactly what steps I took to get Laravel up and running on OSX Yosemite.

Laravel 有很好的安装 Laravel文档。我将详细介绍在 OSX Yosemite 上启动和运行 Laravel 所采取的具体步骤。

Install via Laravel Installer. Type the following into terminal.

通过 Laravel 安装程序安装。在终端中输入以下内容。

cd ~/
composer global require "laravel/installer=~1.1"

Add the composer executable to the Path environment, so to that the laravelexecutable can be found.

将 composer 可执行文件添加到 Path 环境中,以便laravel可以找到该可执行文件。

PATH=$PATH:~/.composer/vendor/bin

Install a fresh Laravel instance, and give it a name. In our case we'll name the project saas.

安装一个新的 Laravel 实例,并为其命名。在我们的例子中,我们将项目命名为saas

laravel new saas

I'm using MAMP PROto run sites locally on my mac. So I just need to create a new host in MAMP, and point it to the saas/publicdirectory.

我正在使用MAMP PRO在我的 mac 上本地运行站点。所以我只需要在 MAMP 中创建一个新主机,并将其指向saas/public目录。

laravel_mamp.png

laravel_mamp.png

Then, visiting http://saas:8888will show you Laravel's beautiful welcome screen.

然后,访问http://saas:8888将向您展示 Laravel 漂亮的欢迎屏幕。

laravel5_1.png

laravel5_1.png

3) Create Database

3) 创建数据库

I like to use Navicatto manage my databases. With Navicat for MySQL, I create a new local database.

我喜欢使用Navicat来管理我的数据库。使用 Navicat for MySQL,我创建了一个新的本地数据库。

Then, define it's connection in the .envfile.

然后,在.env文件中定义它的连接。

 DB_HOST=localhost
 DB_DATABASE=saas
 DB_USERNAME=root
 DB_PASSWORD=xxxxxxx

The trigger the migration with the following command:

使用以下命令触发迁移:

php artisan migrate

Since I'm using MAMP, I got this error when trying to migrate.

由于我使用的是 MAMP,因此在尝试迁移时出现此错误。

[PDOException]                                    

SQLSTATE[HY000] [2002] No such file or directory

SQLSTATE[HY000] [2002] 没有那个文件或目录

Solution was to add the unix_socketkey with a value of the path that the mysql.sock resides in MAMP.

解决方案是添加unix_socket具有 mysql.sock 驻留在 MAMP 中的路径值的键

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
        'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
    ],

4) Wrap-UP

4) 总结

Directories within the storage and the bootstrap/cache directories should be writable. We'll do that with the following?

storage 和 bootstrap/cache 目录中的目录应该是可写的。我们会用以下方法做到这一点吗?

chmod -R 777 storage
chmod -R 777 bootstrap/cache

Rename the environment file.

重命名环境文件。

mv .env.example .env

5) PHP Path

5) PHP 路径

Since were using MAMP, we have multiple version of PHP installed on our machine. So if we try to run php artisan, we will be given an error.

由于使用 MAMP,我们在我们的机器上安装了多个版本的 PHP。所以如果我们尝试运行php artisan,我们会得到一个错误。

Mcrypt PHP extension required

If you also receive that error, first check to see what version of PHP your using with MAMP. You can check that through MAMP's Main Window > PHP. In my case, were using version 5.6.10.

如果您也收到该错误,请首先检查您在 MAMP 中使用的 PHP 版本。您可以通过 MAMP 的主窗口 > PHP 进行检查。就我而言,正在使用 version 5.6.10

Then we can edit our ~/.bash_profilefile, by adding the following line:

然后我们可以~/.bash_profile通过添加以下行来编辑我们的文件:

export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH

Restart terminal, and you should then be able to run the php artisancommand.

重新启动终端,然后您应该能够运行该php artisan命令。

And that's it. Create something awesome!

就是这样。创造一些很棒的东西!

回答by Jamie Poole

Adding local configuration to a file like config/database.php seemed wrong to me -- because any changes to it would also be uploaded to a Git repo.

将本地配置添加到像 config/database.php 这样的文件对我来说似乎是错误的——因为对它的任何更改也会上传到 Git 存储库。

Found this other solution that works fine with no code change:

找到了另一个无需更改代码即可正常工作的解决方案:

mkdir /var/mysql
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

This worked instantly and no changes to PHP or Git-able files.

这立即生效,并且不会更改 PHP 或 Git 文件。

Hope it helps.

希望能帮助到你。

回答by Prasanth

Laravel Framework 5.7 Installation on Mac os with MAMP

使用 MAMP 在 Mac os 上安装 Laravel Framework 5.7

ComposerComposer installation

作曲家作曲家安装

curl -sS https://getcomposer.org/installer | php

Installing laravel

安装 Laravel

  1. composer global require laravel/installer
  2. PATH=$PATH:~/.composer/vendor/bin
  3. laravel new
  1. composer global 需要 laravel/安装程序
  2. PATH=$PATH:~/.composer/vendor/bin
  3. 拉拉新

chmod -R 775 storage chmod -R 775 bootstrap/cache

chmod -R 775 存储 chmod -R 775 引导/缓存

After i got 500 error

在我得到 500 错误之后

checked error log found following error

检查错误日志发现以下错误

tail -f /Applications/MAMP/logs/php_error.log

Found :syntax error, unexpected '=' blog/vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 388

发现:语法错误,意外的“=” blog/vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 388

I changed my php version 7.1 solved my problem

我更改了 php 版本 7.1 解决了我的问题