Go to project dir and create composer.json

{
    "require": {
        "symfony/console": "^3.1",
        "symfony/finder": "^3.1",
        "psr/log": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "": "src/"
        }
    }
}

Then run install:

composer install

Create application script file and make it executable:

touch areafix
chmod a+x areafix

Content of areafix file:

#!/usr/bin/env php

<?php
// set to run indefinitely if needed
set_time_limit(0);

/* Optional. It’s better to do it in the php.ini file */
date_default_timezone_set('Europe/Kiev');.

// include the composer autoloader
require_once __DIR__ . '/vendor/autoload.php';.

// import the Symfony Console Application.
use Symfony\Component\Console\Application;.
use Commands\GreetCommand;

$app = new Application();
$app->add(new GreetCommand());
$app->run();
?>

I put my commands to src/Commands. Command example (from http://symfony.com/doc/current/components/console/introduction.html#creating-a-basic-command):

namespace Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GreetCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('demo:greet')
            ->setDescription('Greet someone')
            ->addArgument(
                'name',
                InputArgument::OPTIONAL,
                'Who do you want to greet?'
            )
            ->addOption(
               'yell',
               null,
               InputOption::VALUE_NONE,
               'If set, the task will yell in uppercase letters'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        if ($name) {
            $text = 'Hello '.$name;
        } else {
            $text = 'Hello';
        }

        if ($input->getOption('yell')) {
            $text = strtoupper($text);
        }

        $output->writeln($text);
    }
}

 

1468609260