一招轻松搞定 Composer 全局安装

作者: 何朱必 分类: 开发笔记 发布时间: 2017-06-12 14:09 ė views 6 132条评论

附件压缩包下载

先要设置好 Windows 系统搜索路径环境变量,也就是把你的php安装目录,比方说“d:\phpRE\php\;”“d:\phpRE\php\ext\;”添加到“环境变量”路径中,实现全局安装以生成最新的“composer.phar”依赖包。

快捷安装:关闭防火墙→将 “Composer-Setup.exe” 复制到 PHP 的安装目录下面,也就是和 php.exe 在同一级目录→运行“Composer-Setup.exe”安装composer→用shift+右键打开当前命令窗口输入命令:php composer_installer.phar 正式安装composer.phar

如果用win32的Composer-Setup.exe安装不成功,就换成下面的几步自定义安装方法,也可以轻松搞定 Composer 全局安装:

“composer_installer.phar”+”composer.cmd”到php目录下→用shift+右键打开当前命令窗口输入命令:

php composer_installer.phar→生成最新的依赖包”composer.phar”→你需要使用 composer 部署第三方Apps时就在应用目录下(必须与composer.json文件同在根目录)shift+右键打开当前命令窗口→用命令“composer install/update”轻松下载安装/更新和部署Apps就OK了

具体应用:

①全局安装成功后可使用Comporser创建开发项目的目录架构。composer install命令是将项目所有的依赖包下载到本项目vendor目录下,而通过composer create-project <框架等依赖包原始名字>/<默认名字> <别名> <项目名> <版本号>  命令则是将所有的代码及其依赖的包放到所命名的项目目录下,相当于执行了一个git clone命令),然后再打开此项目目录进行PhpStom本地开发和远程测试。

②在 composer.json 文件中列出你项目所需的依赖包,加上一点简单的命令,Composer 将会自动帮你下载并设置你的项目依赖。composer require 这个指令会增加一个项目依赖,如果你还没有 composer.json 文件, 将会创建一个。下面的例子将为项目加入 Twig 依赖。

composer require twig/twig:~1.8

上面举例是需要一个版本为 ~1.8 ,意味着 “任何大于 1.8.0 ,但小于 2.0.x-dev 的版本”。你也可以使用通配符 * 在 1.8.* 之中。Composer在composer update 时将升级你的所有依赖到你限制的最新版本。

③ composer init 命令将会引导你创建一个完整的 composer.json 文件到你的项目之中。无论你使用哪种方式,一旦你创建了 composer.json 文件,你可以告诉 Composer 去下载及安装或更新升级你的依赖到 /vendor/ 目录中。

④依赖包更新通知:要接收关于新版本的更新通知。你可以注册 VersionEye,这个 web 服务可以监控你的 Github 及 BitBucket 帐号中的 composer.json 文件,并且当包有新更新时会发送邮件给你。

⑤程序中自动加载composer简单方法:只需要在引用文件中,加入下面一行引用代码

require_once __DIR__.’/vendor/autoload.php’;

⑥可以在根目录下用命令composer config repo.packagist composer https://packagist.phpcomposer.com修改composer.json配置文件来更换镜像源以快速获取国内镜像。也可经常执行 composer selfupdate 检查更新以保持 Composer 一直是最新版本。

本文出自何朱必博客,转载时请注明出处及相应链接。

本文永久链接: http://www.hezhubi.com/composer.htm

132条评论

  1. Minerva 2019年7月24日 下午5:42 回复

    Hello colleagues, its wonderful paragraph regarding tutoringand entirely defined, keep it up all the time.

  2. Seymour 2019年7月24日 下午4:37 回复

    Highly energetic post, I enjoyed that a lot. Will there be a part 2?

  3. Jodi 2019年7月24日 上午9:38 回复

    Hi! Would you mind if I share your blog
    with my twitter group? There’s a lot of people that I think would really appreciate your content.
    Please let me know. Many thanks

  4. Mellissa 2019年7月24日 上午8:40 回复

    It’s very easy to find out any matter on net as compared to
    books, as I found this piece of writing at this site.

  5. Lorri 2019年7月24日 上午3:12 回复

    Howdy are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my
    own. Do you need any coding knowledge to make your own blog?
    Any help would be really appreciated!

  6. Latrice 2019年7月23日 下午4:35 回复

    Very nice post. I simply stumbled upon your weblog and wanted to mention that I’ve
    truly enjoyed surfing around your blog posts. In any case I will be subscribing
    in your feed and I hope you write again very soon!

  7. Kassie 2019年7月23日 下午2:06 回复

    This is really interesting, You are a very skilled
    blogger. I’ve joined your rss feed and look forward to seeking more of your excellent post.
    Also, I’ve shared your web site in my social networks!

  8. Gay 2019年7月23日 上午4:57 回复

    Hi Dear, are you in fact visiting this website daily, if so then you will absolutely take good knowledge.

  9. Elsa 2019年7月23日 上午4:25 回复

    That is a great tip particularly to those new to the
    blogosphere. Brief but very precise information… Thanks for sharing this one.
    A must read article!

  10. Benjamin 2019年7月23日 上午3:40 回复

    Thanks for finally writing about >一招轻松搞定 Composer 全局安装 <Liked it!

  11. Catalina 2019年7月23日 上午2:43 回复

    Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is important and all. But imagine if you added some
    great photos or videos to give your posts more, “pop”! Your content is excellent but
    with images and video clips, this blog could definitely be one of the greatest in its niche.
    Superb blog!

  12. Kenneth 2019年7月23日 上午1:26 回复

    You can certainly see your skills in the article you write.
    The world hopes for more passionate writers such as you who are not
    afraid to mention how they believe. All the time go after your
    heart.

  13. Thanh 2019年7月22日 下午11:30 回复

    My brother suggested I might like this website.

    He was entirely right. This post truly made my day.
    You can not imagine just how much time I had spent for this info!
    Thanks!

  14. Noella 2019年7月22日 下午8:56 回复

    Hmm it seems like your blog ate my first comment
    (it was super long) so I guess I’ll just sum it up what I submitted and say, I’m
    thoroughly enjoying your blog. I as well am an aspiring
    blog writer but I’m still new to everything.
    Do you have any helpful hints for inexperienced blog
    writers? I’d genuinely appreciate it.

  15. Olga 2019年7月22日 下午5:41 回复

    Hi there very cool web site!! Man .. Beautiful ..
    Amazing .. I will bookmark your web site and take the feeds additionally?
    I’m happy to search out numerous helpful information right here
    within the put up, we’d like work out more techniques on this regard,
    thanks for sharing. . . . . .

  16. Charmain 2019年7月22日 下午5:24 回复

    Wonderful goods from you, man. I’ve understand your stuff previous to and you are just too excellent.
    I actually like what you have acquired here, really like what you are saying and the way in which you say
    it. You make it enjoyable and you still care for
    to keep it sensible. I can’t wait to read much more from you.
    This is actually a wonderful web site.

  17. Adelaide 2019年7月22日 下午3:27 回复

    Quality articles is the crucial to attract
    the viewers to visit the web page, that’s what this web site is providing.

  18. Mayra 2019年7月22日 下午3:05 回复

    Very nice post. I just stumbled upon your weblog and wished to
    mention that I’ve truly enjoyed surfing around your weblog posts.
    In any case I’ll be subscribing on your rss feed and I hope
    you write again very soon!

  19. Roxana 2019年7月22日 下午2:37 回复

    Hey! I know this is kinda off topic nevertheless I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa?
    My site discusses a lot of the same subjects as yours and I feel we could greatly benefit from each other.
    If you’re interested feel free to shoot
    me an e-mail. I look forward to hearing from you!
    Great blog by the way!

  20. Gail 2019年7月22日 下午1:45 回复

    Terrific article! This is the type of information that are supposed to be shared across the net.
    Shame on Google for no longer positioning this post upper!

    Come on over and visit my website . Thank
    you =)

  21. Emery 2019年7月22日 下午12:11 回复

    Hi there, this weekend is fastidious in favor of me, for the reason that
    this moment i am reading this wonderful informative post here at my home.

  22. Arnulfo 2019年7月22日 下午12:05 回复

    Your style is really unique compared to other folks I’ve
    read stuff from. Many thanks for posting when you have the opportunity, Guess I’ll just
    bookmark this web site.

  23. Dominga 2019年7月22日 上午7:35 回复

    Hi, everything is going perfectly here and ofcourse every one
    is sharing facts, that’s really good, keep up writing.

  24. Gilberto 2019年7月22日 上午7:05 回复

    Thanks on your marvelous posting! I certainly enjoyed reading
    it, you might be a great author.I will always bookmark your
    blog and definitely will come back down the road.
    I want to encourage you to continue your great work, have
    a nice afternoon!

  25. Wanda 2019年7月22日 上午6:31 回复

    Just want to say your article is as amazing. The clearness in your post is simply nice and i can assume you’re an expert on this
    subject. Fine with your permission let me to grab your RSS feed to keep updated with
    forthcoming post. Thanks a million and please keep up the
    gratifying work.

  26. Gudrun 2019年7月22日 上午2:33 回复

    I’m not that much of a internet reader to be honest but your sites really nice, keep
    it up! I’ll go ahead and bookmark your website to come back later.
    All the best

  27. Maryanne 2019年7月21日 下午10:53 回复

    I am curious to find out what blog system you
    have been working with? I’m experiencing some small security issues with my latest blog and I would like to
    find something more secure. Do you have any solutions?

  28. Russell 2019年7月21日 下午10:17 回复

    magnificent points altogether, you just gained a emblem new reader.
    What may you suggest about your put up that you simply made a few days in the past?
    Any positive?

  29. Bridgette 2019年7月21日 下午10:07 回复

    Thank you for any other informative web site.
    The place else could I am getting that type of info written in such
    a perfect manner? I have a venture that I’m simply now running
    on, and I’ve been on the look out for such info.

  30. Phillip 2019年7月21日 下午6:05 回复

    Hey I know this is off topic but I was wondering if you knew of
    any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and
    was hoping maybe you would have some experience with
    something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward
    to your new updates.

  31. Evelyne 2019年7月21日 上午11:55 回复

    My partner and I stumbled over here by a different web address and thought I might check things out.
    I like what I see so now i am following you.
    Look forward to looking into your web page for a second time.

  32. Shannan 2019年7月21日 上午10:20 回复

    Howdy! This post couldn’t be written any better!
    Reading this post reminds me of my old room mate!
    He always kept talking about this. I will forward this write-up to
    him. Fairly certain he will have a good read. Thank you for
    sharing!

发表评论

电子邮件地址不会被公开。

Ɣ回顶部