Building PHP Composer Package

Lasantha Sanjeewa

--

Firstly create an empty directory. Next, generate a composer file using the following command.

composer init

Next, you want to type the following details. Please consider Package Type as the library and give the license as MIT.

composer init

Next, inside the src folder create index.php and add the following code sample.

Next, push this directory as a GitHub repository.

git push

Next, go to https://packagist.org/ and sign up using GitHub.

packagist home page

Next, click submit button on packagist home page. Add git hub repository URL and hit the check button.

packagist check

Next, click submit button.

packagist submit

Finally, you can see your composer package is created successfully.

packagist dashboard

Finally, create a testing directory. Copy “composer require sanje/php-composer” command and after that paste this command inside this directory.

terminal error

If you see this error. You can fix it by adding git tags following.

git tags

Next, try again to composer the command following.

composer package install

Now you can create a simple index.php file inside the root directory and add the following code.

Open the testing project using the terminal and run index.php file. You can see your output.

output

References: https://github.com/sanju2/php-composer

Thank You!!!

--

--

No responses yet