[email protected]
Twitter
LinkedIn
YouTube
GitHub
  • Services
  • Blog
  • Repositories
  • GitHub
  • Resume
  • Contact
Product was added to your cart

Cart

Run Symfony2 command from cronjobs in CPanel on a shared host

September 18, 2015Back-End, Tricksjfadev

Let's see how to program tasks scheduled in CPanel shared hosting to run custom commands of Symfony2.

In our example we will have the following file structure of our Symfony project in our shared server:

/home/{username}
|
|- /app
|- /src
|  |
|  |- /AppBundle
|  |
|  |- /Command
|     |
|     |-TestCommand.php
|
|- /vendor
|- /public_html
|  |
|  |- app.php
|
|- test_command.log

/src/AppBundle/Command/TestCommand.php

<?php

namespace AppBundle\Command; 

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
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 TestCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('my:test:run');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Welcome World!');
    }
}

Now we run each time our command and to save the result in the test_command.log file. To do this just go in our CPanel:

Home >  Advanced > Cron Jobs

Minute: 0
Hour: *
Day: *
Month: *
Weekday: *

Command: /usr/bin/php -q /home/{username}/app/console my:test:run >/home/{username}/test_command.log

Replace {username} by your user name on your shared hosting account.

: Commands, Console, CPanel, Cronjobs, Framework, PHP, Symfony2

Services

  • Excel2chatGPT $10.00
  • Bot Tok $45.00
  • Fix bugs in your PHP Symfony App $70.00 / hr
  • Fix bugs in your Wordpress Site $70.00 / hr
  • Tasks Automation using Node.js $70.00 / hr

Blog

  • How to Pay with a Bank Card on Cryptomus
  • Complete Beginner’s Guide to Bot Tok: Terminal Commands Explained
  • Top Site to Gain Views on TikTok
  • Jfa Whatsapp Chatbot
  • TikTok Bot

Explore

  • Free 10 Tiktok Likes
  • Free 2K TikTok Views
  • Free 100 TikTok Favorites
  • Free 300 TikTok Shares
  • Buy TikTok Views
  • Free 100 Instagram Likes
Twitter
LinkedIn
YouTube
GitHub

© 2013-2025 Jordi Fernandes Alves (@jfadev)