Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Creating Symlinks to Libraries in Composer

Creating Symlinks to Libraries in Composer

0

When developing a new library in PHP, it’s sometimes useful to symlink the library into a project, rather than including the repository URL or Packagist link. That way, you can test the library out before committing the code.

Luckily, Composer provides an easy way to create a symlink in your project.

Composer Config for Git Repo

Let’s start with linking your project to your git-hosted library (useful if you haven’t published your library to Packagist). Simply add the following code to your composer.json file:

// ...
"repositories": [
      {
        "url": "git@github.com:niraj-shah/your-library.git",
        "type": "git"
    ],
// ...
"require": {
    "php": "^7.1.3",
    // ...
    "niraj-shah/your-library": "@dev",
    // ...
},
// ...

Once you’ve added the link to the repo, include the package name and version in the require block (as shown above). Once you’ve updated the config, run composer update to update the libraries in your project, and download the code from your git repo.

Composer Config for Local Folder (using Symlink)

If your library isn’t in a repo, or you rather work from a local version of the library (during development of the library), symlink is a great option to make sure the library is up to date with the dev version.

The below config creates a symlink in the vendor folder, pointing to the local version of the library. The symlink means it’s essentially a shortcut to the folder (not a copy). Any changes you make to the library will immediately be reflected in your project, making development much easier (no more having to run composer update for every change you make).

// ...
"repositories": [
  {
    "url": "/home/vagrant/code/your-library",
    "type": "path",
    "options": {
          "symlink": true
      }
  }
],
// ...
"require": {
    "php": "^7.1.3",
    // ...
    "niraj-shah/your-library": "@dev",
    // ...
},
// ...

As before, you need to remember to add the library package name to the require block. Run composer update to setup the symlink after updating the composer config – you don’t need to run the update again unless you want to update the other libraries in your project.

Composer, Development, PHP, Tutorial

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Gadget Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy