Blogger Information
Blog 40
fans 0
comment 1
visits 39760
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 熟悉composer安装及命令, 用laravel框架建一个项目
Dong.
Original
848 people have browsed it

一、熟悉composer安装及命令使用

序号 命令 作用
1 composer install 添加依赖信息到composer.json
2 composer update 更新composer.json这个文件,那么composer.lock里的版本就重写了
3 composer require 使用composer require components/jquery来生成vendor文件,components文件,composer文件,autoload.php文件,还生成了composer.lock,用来锁定版本号
4 composer create-project 用来建目录,项目

二、安装思路

  1. VSCode里安装
  2. 终端-新终端-pwd查看当前路径,是否在当前项目
  3. cd 0806
  4. pwd
  5. php -v拿到当前php版本
  6. clear清屏
  7. https://pkg.phpcomposer.com/#how-to-install-composer
  8. CA证书安装
  9. https://curl.haxx.se/docs/caextract.html
  10. php.ini里查找:openssl.cafile=
  11. openssl.cafile=D:/phpstudy_pro/cacert.pem
  12. https://pkg.phpcomposer.com/#how-to-install-composer
  13. 复制以下指令进行下载:
  14. php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
  15. 得到一个安装器:composer-setup.php
  16. 下载安装
  17. php composer-setup.php
  18. 得到composer.phar,它是多个php文件的压缩文档
  19. 下面这条命令是删除composer-setup.php
  20. php -r "unlink('composer-setup.php');"
  21. 查看composer.phar版本号:
  22. php composer.phar -v
  23. Composer version 1.10.10
  24. 批处理composer.bat
  25. 把以下指令放入
  26. @php "%~dp0composer.phar" %*
  27. 执行以下测试
  28. composer init
  29. 中国全量镜像,用来加速
  30. composer config -g repo.packagist composer https://packagist.phpcomposer.com
  31. 升级版本
  32. composer selfupdate
  33. 创建composer.json
  34. Package name (<vendor>/<name>) [melinda/0806]: phpcn/melinda
  35. Description []: test
  36. Author [, n to skip]: melinda <melinda@php.cn>
  37. Minimum Stability []: 这里是一些版权信息
  38. Package Type (e.g. library, project, metapackage, composer-plugin) []: 这里是一些插件和依赖
  39. License []: MIT(问项目基于什么样的协议)
  40. Define your dependencies.
  41. Would you like to define your dependencies (require) interactively [yes]? bootstrap(安装什么依赖)
  42. Please answer yes, y, no, or n.
  43. Would you like to define your dependencies (require) interactively [yes]? no
  44. Would you like to define your dev dependencies (require-dev) interactively [yes]? no
  45. {
  46. "name": "phpcn/melinda",
  47. "description": "test",
  48. "license": "MIT",
  49. "authors": [
  50. {
  51. "name": "melinda",
  52. "email": "melinda@php.cn"
  53. }
  54. ],
  55. "require": {}
  56. }
  57. Do you confirm generation [yes]?yes
  58. 然后就生成了composer.json文件,以下是内容,这种是交互方式,一般不用
  59. {
  60. "name": "phpcn/melinda",
  61. "description": "test",
  62. "license": "MIT",
  63. "authors": [
  64. {
  65. "name": "melinda",
  66. "email": "melinda@php.cn"
  67. }
  68. ],
  69. "require": {}
  70. }
  71. -----------------------------------------------------------------
  72. https://packagist.org/
  73. 搜索jquery
  74. components/jquery
  75. composer.json文件手动创建一个,以下是内容
  76. {
  77. "name": "phpcn/demo",
  78. "require": {
  79. "components/jquery": "3.4.*"
  80. }
  81. }
  82. -----------------------------------------------------------------------
  83. 新建终端,命令:composer install添加依赖信息
  84. 生成vendor文件,components文件,composer文件
  85. autoload.php很重要
  86. 还生成了composer.lock,用来锁定版本号,同样的环境开发工作
  87. 如果后面composer升级,就要把composer.lock删除后,再重新安装
  88. 还可以用composer update命令来更新composer.json这个文件,那么composer.lock里的版本就重写了
  89. ---------------------------------------
  90. vendorcomposer.jsoncomposer.lock都删除
  91. 在新终端用下面的命令重新生成被删除的文件
  92. composer require components/jquery
  93. 用以下命令强制更新版本号
  94. composer require components/jquery "3.4.1"
  95. 建目录为博客
  96. 输入指令:
  97. composer create-project laravel/Laravel blogs
  98. 版本6
  99. composer create-project --prefer-dist laravel/laravel blog 6.*

二、用laravel框架建一个项目

  • laraver框架网站:官网链接
  • 复制:composer create-project laravel/laravel
  • 在VCCode里,点击终端,新终端,输入指令:composer create-project laravel/Laravel blogs 回车等待

总结

  • 了解composer原理与安装,使用 php 开发的包依赖管理工具 (php 5.3.2+)
  • 了解Laravel开发框架:是典型的基于组件开发的 PHP 开发框架
  • 通过composer下载的组件统一保存在vendor目录中
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:composer是工作最常用的工具之一
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post