简体   繁体   English

使用Composer安装PHP项目依赖项

[英]Installing PHP Project Dependencies with Composer

I am trying to install Nette2.3.1 using Composer (on XAMPP). 我正在尝试使用Composer(在XAMPP上)安装Nette2.3.1。 In c:\\x\\php folder I run this command: 在c:\\ x \\ php文件夹中,运行以下命令:

composer create-project nette/sandbox myprojectname

When I do this, getting following error: 当我这样做时,出现以下错误:

[Seld\\JsonLint\\ParsingException] "c:\\x\\php\\php.exe" does not contain valid JSON Parse error on line 1: MZÉ ♥ ♦ ╕ ^ Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[' [Seld \\ JsonLint \\ ParsingException]“ c:\\ x \\ php \\ php.exe”在第1行上不包含有效的JSON解析错误:MZÉ♥♦^ ^预期之一:“ STRING”,“ NUMBER”,“ NULL” , '真假', '{', '['

I tried all these options to no avail: 我尝试了所有这些选项都无济于事:

  1. removed the project directory and tried 删除项目目录并尝试
  2. ran this command inside htdocs folder 在htdocs文件夹中运行此命令
  3. ran this through PHP JetBrains console 通过PHP JetBrains控制台运行
  4. made sure that the Composer version is the latest one 确保Composer版本是最新版本

What was wrong? 什么问题?

This was what went wrong: 这是出问题的地方:

  1. I installed xampp while anti-virus is running - i got a warning but chose to ignore that. 我在运行防病毒软件时安装了xampp-我收到警告,但选择忽略该警告。 Consequently php.exe was corrupted and messed up the whole thing for me. 因此,php.exe损坏并为我弄乱了整个内容。

  2. PATH variables under my user wasn't updated with php.exe path. 我的用户下的PATH变量未使用php.exe路径更新。 Though system variable is updated, it is still a mystery to me why this became an issue. 尽管系统变量已更新,但对我来说仍然是一个谜,为什么这成为问题。

How I did to correct this: 我如何纠正此问题:

Removed xampp altogether, cleared composer cache and installed wamp this time and created project for nette sandbox. 完全删除了xampp,清除了作曲家缓存,这次安装了wamp,并为nette沙箱创建了项目。 This worked fine. 这很好。 In all fairness xampp would have worked as well had I installed it with av disabled and PATH variables properly updated. 公平地说,如果我在禁用av并正确更新PATH变量的情况下进行安装,xampp也会正常工作。

I think your composer PATH or shortcut/batch file is kind of broken, because it tries to read the php.exe file as a JSON file. 我认为您的作曲者PATH或快捷方式/批处理文件已损坏,因为它尝试将php.exe文件读取为JSON文件。

Try to remove composer completely and start with a clean install 尝试完全删除composer并开始进行全新安装

  1. Download and install composer using the automated installer . 使用自动安装程序下载并安装作曲家。 It sets up the PATH for you, so you can just call composer from anywhere. 它为您设置了PATH,因此您可以从任何地方调用composer。
  2. Close the command line terminal and start a new one (important). 关闭命令行终端,然后启动一个新的终端(重要)。
  3. Try to run the composer create-project nette/sandbox myprojectname command in any directory 尝试在任何目录中运行composer create-project nette/sandbox myprojectname命令

Documentation - windows installation of composer 文档-Windows Composer安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM