使用 Composer 安装 Laravel

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

Install Laravel using Composer

laravelcomposer-php

提问by FahadAkram

I'm trying to install Laravel using Composer, but after running the following command

我正在尝试使用Composer安装 Laravel ,但在运行以下命令后

composer create-project laravel/laravel cmsLaravel 5.2

pointing to my c/xampp/htddocsdirectory, I get the error below:

指向我的c/xampp/htddocs目录,我收到以下错误:

C:\xampp\htdocs\laravelCMS\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\laravelCMS\bootstrap\autoload.php on line 17

C:\xampp\htdocs\laravelCMS\bootstrap/../vendor/autoload.php): 无法打开流:第 17 行的 C:\xampp\htdocs\laravelCMS\bootstrap\autoload.php 中没有这样的文件或目录

回答by nyedidikeke

To install Laravel using composer, all you need to do is to run in your terminal is:

要使用 composer 安装 Laravel,您需要做的就是在终端中运行:

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

Where: blogis the name of the folder containing your new Laravel instance.

其中:blog是包含新 Laravel 实例的文件夹的名称。

To install Laravel directly within your chosen directory (not in a folder within it as demonstrated above), simply run the same command but this time without a folder name as in:

要直接在您选择的目录中安装 Laravel(而不是在上面演示的文件夹中),只需运行相同的命令,但这次没有文件夹名称,如下所示:

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

Remember to run the command within your desired directory for the project; in your case, for C:\xampp\htdocs\, then, run either the first or second command as above base on your needs.

请记住在项目所需的目录中运行该命令;在您的情况下, for C:\xampp\htdocs\,然后,根据您的需要运行上述第一个或第二个命令。

This assumes you already have Composer properly installed as recommended on their website.

这假设您已经按照他们网站上的建议正确安装了 Composer 。

Before you try addressing your failed to open stream:error, do avoid having folder names with space(s) as in your command above (obviously not the source of the error).

在尝试解决failed to open stream:错误之前,请避免使用上面命令中包含空格的文件夹名称(显然不是错误的根源)。

Make sure you have the correct Server Requirements for Laravel
the failed to open stream:error usually occur when the OpenSSL PHP Extension not enabled.

请确保您有Laravel正确的服务器要求
failed to open stream:不启用OpenSSL的PHP扩展的错误时,通常会出现。

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • PHP >= 5.6.4
  • OpenSSL PHP 扩展
  • PDO PHP 扩展
  • Mbstring PHP 扩展
  • 分词器 PHP 扩展
  • XML PHP 扩展

After enabling the required extension(s), do remember to restart your server, then run the following command:

启用所需的扩展后,请记住重新启动服务器,然后运行以下命令:

composer update

回答by Aashish

Follow the steps below;

请按照以下步骤操作;

  1. Download and install Composer.
  2. Go inside the folder C:\xampp\htdocs>(if you are using xampp) or C:\wamp\www>(if you are using wamp) and open cmd/PoweShell & run the following commands:

    • composer global require "laravel/installer"
    • composer create-project laravel/laravel(after running this command a folder having name Laravel will be created there)
    • Now go inside Laravel folder and run php artisan servecommand.
  3. After executing the last cmd, it will show an URL: http://127.0.0.1:8000; access the URL in a browser, which should reflect the will see the default webpage of Laravel.

  1. 下载并安装Composer
  2. 进入文件夹C:\xampp\htdocs>(如果您使用的是 xampp)或C:\wamp\www>(如果您使用的是 wamp)并打开 cmd/PoweShell 并运行以下命令:

    • composer global require "laravel/installer"
    • composer create-project laravel/laravel(运行此命令后,将在那里创建一个名为 Laravel 的文件夹)
    • 现在进入 Laravel 文件夹并运行php artisan serve命令。
  3. 执行最后一个后cmd,会显示一个 URL: http://127.0.0.1:8000; 在浏览器中访问 URL,这应该反映将看到 Laravel 的默认网页。

回答by efraim

You can just run

你可以跑

composer install

作曲家安装

and it will process the required files to load the laravel in web browser

它将处理所需的文件以在 Web 浏览器中加载 Laravel

EDIT:

编辑:

After seeing your comment, you should go to your laravel directory in your cmd.

看到您的评论后,您应该转到 cmd 中的 laravel 目录。

cd C:\xampp\htdocs\laravelCMS

cd C:\xampp\htdocs\laravelCMS

and run the command

并运行命令

composer install

作曲家安装

回答by Mateus Sobral

  1. Download and install composer
  2. Run composer global require "laravel/installer"
  3. Open terminal inside C:\xampp\htdocs and run laravel new my_folder_name
  1. 下载并安装作曲家
  2. composer global require "laravel/installer"
  3. 在 C:\xampp\htdocs 中打开终端并运行 laravel new my_folder_name

回答by kendra mukhia

Check your index.php and Change the path as per your project directory

检查您的 index.php 并根据您的项目目录更改路径

Register The Auto Loader

注册自动加载程序

require __DIR__.'/cmsLaravel /vendor/autoload.php'; 
$app =require_once __DIR__.'/cmsLaravel /bootstrap/app.php';

回答by Afshn

Change your command to this:

将您的命令更改为:

composer create-project laravel/laravel cmsLaravel 5.2.*

This mean any sub version of laravel 5.2.

这意味着laravel 5.2.

回答by Technology Inspirations

composer create-project laravel/laravel 6.0

作曲家创建项目 laravel/laravel 6.0

composeris a tool for dependency management in PHP

composer是一个 PHP 依赖管理工具

create-projectis command to create a new laravel project

create-project是创建一个新的 Laravel 项目的命令

laravel/laravelis for the skeleton application you get when creating a new project. It provides a default structure that's recommended (you're not forced to use it). The repository contains default config files, controllers, routes, etc. As well as code responsible for bootstrapping the application.

laravel/laravel用于创建新项目时获得的骨架应用程序。它提供了推荐的默认结构(您不必强制使用它)。存储库包含默认配置文件、控制器、路由等。以及负责引导应用程序的代码。

Link Laravel/laravel

链接Laravel/laravel

6.0Version in laravel

Laravel 6.0版本