【问题标题】:Installing and Running Laravel安装和运行 Laravel
【发布时间】:2017-11-24 22:04:45
【问题描述】:

我对使用命令行感到非常陌生和沮丧。我目前正在尝试安装 laravel 以与我的 PHP 应用程序一起使用。我已经安装了 composer,现在我正在尝试安装 laravel。

我首先尝试按照 documentation for laravel 上的说明进行操作:

  • 已安装作曲家
  • composer global require "laravel/installer"
  • 运行失败laravel new blog:-bash: laravel: command not found

接下来我尝试关注 laracast video

  • 已安装作曲家
  • composer global require "laravel/installer"
  • 打开vim ~/.bashrc 并添加export PATH="$HOME/.composer/vendor/bin:$PATH"
  • 运行失败laravel new blog:-bash: laravel: command not found

除了 laravel 仍然不可用,当我回到 bashrc 文件时,我得到以下通知:

Found a swap file by the name "~/.bashrc.swp"
          owned by: Shawn   dated: Wed Jun 21 16:01:37 2017
         file name: ~Shawn/.bashrc
          modified: YES
         user name: Shawn   host name: Shawns-MBP.domain
        process ID: 39328
While opening file "/Users/Shawn/.bashrc"
             dated: Wed Jun 21 16:19:11 2017
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /Users/Shawn/.bashrc"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/Shawn/.bashrc.swp"
    to avoid this message.

再一次,我对这个过程感到非常困惑,根本无法理解出了什么问题以及为什么它对其他人有效,但我似乎无法正确安装 laravel。

【问题讨论】:

  • 通过附加现有的 with 将作曲家路径添加到 .bash_profile 中:不要忘记重新运行它或简单地注销并重新登录
  • 或者,您也可以通过在终端中发出 Composer create-project 命令来安装 Laravel (laravel.com/docs/5.4/installation#installing-laravel):composer create-project --prefer-dist laravel/laravel blog

标签: php bash macos laravel vim


【解决方案1】:

您的系统找不到laravel 命令。假设您在使用composer global require "laravel/installer" 命令时没有收到任何错误,则安装程序没有更新您系统的已知路径(基本上,它需要知道laravel 映射到~/.composer/vendor/bin/laravel,而现在它没有)。

~/.bashrc 的修改旨在解决此问题,但您需要运行source ~/.bashrc 或注销并重新登录以使对.bashrc 的更改生效。

另一种方式(也是我个人更喜欢的方式)是按照@manian 在 cmets 中所说的方式运行 composer create-project --prefer-dist laravel/laravel blog。这使您无需安装和使用 Laravel 安装程序即可创建 Laravel 项目。

至于你对.swp 文件的问题,那是没有正确退出Vim 的结果。 Vim 创建swp 文件作为备份,以防 Vim 崩溃。 When exited properly,它会删除这些备份文件。但是,如果您不正确地退出 Vim,则无法删除它们。如果您的文件已成功更新并保存,then you can simply delete it

【讨论】:

  • 谢谢你,source ~/.bashrc 解决了这个问题,也感谢你给了我另一种方式。
猜你喜欢
  • 2018-10-19
  • 2018-01-29
  • 1970-01-01
  • 2022-06-23
  • 2017-12-14
  • 1970-01-01
  • 1970-01-01
  • 2011-03-07
  • 2019-04-17
相关资源
最近更新 更多