php 如何安装 Laravel 的 Artisan?

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

How to install Laravel's Artisan?

phplaravel

提问by totymedli

I want to create migrations in Laravel but according to the tutorialsI need the Artisan CLI. The phpcommand works fine and I'm on Windows. I type in php artisanor php artisan listand I get the following error:

我想在 Laravel 中创建迁移,但根据教程我需要 Artisan CLI。该php命令工作正常,我在 Windows 上。我输入php artisanorphp artisan list并收到以下错误:

Could not open input file: artisan

无法打开输入文件:工匠

I wasn't able to find any guide in the documentationnor in Google. How can I install Artisan?

我无法在文档或 Google 中找到任何指南。如何安装 Artisan?

回答by totymedli

Use the project's root folder

使用项目的根文件夹

Artisan comes with Laravel by default, if your phpcommand works fine, then the only thing you need to do is to navigate to the project's root folder. The root folder is the parent folder of the appfolder. For example:

Artisan 默认与 Laravel 一起提供,如果您的php命令工作正常,那么您唯一需要做的就是导航到项目的根文件夹。根文件夹是文件夹的父文件app。例如:

cd c:\Program Files\xampp\htdocs\your-project-name

Now the php artisan listcommand should work fine, because PHP runs the file called artisanin the project's folder.

现在该php artisan list命令应该可以正常工作了,因为 PHP 运行artisan在项目文件夹中调用的文件。

Install the framework

安装框架

Keep in mind that Artisan runs scripts stored in the vendorfolder, so if you installed Laravel without Composer, like downloading and extracting the Laravel GitHub repo, then you don't have the framework itself and you may get the following error when you try to use Artisan:

请记住,Artisan 运行存储在vendor文件夹中的脚本,所以如果你安装了没有 Composer 的 Laravel,比如下载和解压Laravel GitHub repo,那么你没有框架本身,当你尝试使用时可能会出现以下错误工匠:

Could not open input file: artisan

无法打开输入文件:工匠

To solve this you have to install the framework itself by running composer installin your project's root folder.

要解决此问题,您必须通过composer install在项目的根文件夹中运行来安装框架本身。

回答by oliiix

You just have to read the laravel installation page:

你只需要阅读 Laravel 安装页面:

  1. Install Composer if not already installed
  2. Open a command line and do:
  1. 如果尚未安装,请安装 Composer
  2. 打开命令行并执行以下操作:
composer global require "laravel/installer"

Inside your htdocs or www directory, use either:

在您的 htdocs 或 www 目录中,使用:

laravel new appName

(this can lead to an error on windows computers while using latest Laravel (1.3.2)) or:

(这可能会导致 Windows 计算机在使用最新的 Laravel (1.3.2) 时出错)或:

composer create-project --prefer-dist laravel/laravel appName

(this works also on windows) to create a project called "appName".

(这也适用于 Windows)来创建一个名为“appName”的项目。

To use "php artisan xyz" you have to be inside your project root! as artisan is a file php is going to use... Simple as that ;)

要使用“php artisan xyz”,您必须在项目根目录中!因为工匠是 php 将要使用的文件......就这么简单;)

回答by Jaymin

While you are working with Laravel you must be in root of laravel directory structure. There are App, route, public etc folders is root directory. Just follow below step to fix issue. check composer status using : composer -v

当您使用 Laravel 时,您必须位于 Laravel 目录结构的根目录中。根目录下有App、route、public等文件夹。只需按照以下步骤解决问题。使用以下命令检查作曲家状态:composer -v

First, download the Laravel installer using Composer:

首先,使用 Composer 下载 Laravel 安装程序:

composer global require "laravel/installer"

Please check with below command:

请检查以下命令:

php artisan serve

still not work then create new project with existing code. using LINK

仍然不起作用,然后使用现有代码创建新项目。使用链接

回答by Aryan Dubey

Explanation: When you install a new laravel project on your folder(for example myfolder) using the composer, it installs the complete laravel project inside your folder(myfolder/laravel) than artisan is inside laravel.that's, why you see an error,

说明:当您使用 Composer 在您的文件夹(例如 myfolder)上安装新的 Laravel 项目时,它会在您的文件夹(myfolder/laravel)中安装完整的 Laravel 项目,而不是 artisan 在 Laravel 中。这就是为什么您会看到错误,

Could not open input file: artisan

无法打开输入文件:工匠

Solution: You have to go inside by command prompt to that location or move laravel files inside your folder.

解决方案:您必须通过命令提示符进入该位置或将 Laravel 文件移动到您的文件夹中。

回答by user3998741

in laravel, artisan is a file under root/protected page

在laravel中,工匠是根/受保护页面下的文件

for example,

例如,

c:\xampp\htdocs\my_project\protected\artisan

c:\xampp\htdocs\my_project\protected\artisan

you can view the content of "artisan" file with any text editor, it's a php command syntax

您可以使用任何文本编辑器查看“artisan”文件的内容,它是一种 php 命令语法

so when we type

所以当我们打字的时候

php artisan

php工匠

we tell php to run php script in "artisan" file

我们告诉 php 在“工匠”文件中运行 php 脚本

for example:

例如:

php artisan change

php工匠改变

will show the change of current laravel version

将显示当前 Laravel 版本的变化

to see the other option, just type

要查看其他选项,只需键入

php artisan

php工匠

回答by Ehsanz Prof01

REMEMBER THIS!!: when you have installed Composer successfully, you already have Artisan with it...hope it helps all the noobs !!

记住这一点!!:当您成功安装 Composer 时,您已经拥有 Artisan 了...希望它对所有菜鸟有所帮助!!