I'm trying to set up a CRON job to make some database changes on a CodeIgniter install and having issues with the host that are stopping it from working. The host's CRON setup only allows you to execute a PHP file rather than calling a URL.
What I've tried:
Curl, wget, file_get_contents, fopen, http_get from a static PHP file - all not allowed by the host
/path/to/php /path/to/index.php controller method - to use the command line interface
After unfruitful conversations with the host I'm out of ideas. Does anyone know how I could call a controller method from a static PHP file without the above?
First of all, I'm assuming you are using CI ver 2> (CLI support was not available before).
Secondly, lets say that the page you are trying to fire under cron is http://www.mysite.com/index.php/cronjobs/thejob
The correct command would be:
/usr/bin/php /var/www/rootCIfolder/index.php cronjobs thejob
Replace /usr/bin/php with the location of your php executable and /var/www/rootCIfolder with the location of your CI folder.
You need to have php compiled with command line support. You can verify this by:
# php -v
PHP 5.3.3 (cli) (built: Jul 3 2012 16:53:21)
Related
I Just started testing Laravel Vapor, everything working well except I'm using filament package which it needs to run a command to create admin user, the command is working locally on my computer and I have a user now, but in production when I execute the command (./vendor/bin/vapor command production) and then the command that creates the user (php artisan make:filament-user). vapor not giving any input to enter my name and my email address. So is there anyway to give arguments for commands in vapor? or is there anyway to give the these arguments with the command? thank you
simple, just use your command by command line in the console or inside vapor page, menu commands in your project, example:
php artisan <command_name> '<arguments_parameters>'
my job command with argument:
php artisan metric:consolidate '2022-01-29 00:00' (job name with date start argument).
Now I just moved to inmotion from siteground and previously from bluehost. I am trying to set up my laravel(lumen) application on the server. I have been able to get everything else working but the scheduler which I just cannot seem to get to work.
This is the cron job php -q /home/xxxxx/xxxxx/artisan schedule:run which seem to run fine however it fails to execute the queue:work command.
I noticed on my previous hosting I had to edit the Illuminate\Console\Scheduling\Scchedule.php file like this:
return $this->exec("php-cli /home/xxxxx/xxxxx/artisan {$command}", $parameters);
using the regular php command did not work for some reason I had to use php-cli, however with my current hosting it says "command not found" whenever I try to use the php-cli command manually and all my cron job returns in my email is this:
Running scheduled command: php-cli /home/xxxxx/xxxxx/artisan queue:work > '/dev/null' 2>&1 &
I would like to know how I can fix this and get the scheduler to work.
Yes I have php installed. (v7.0)
Yes I have the php-cli package installed. (v7.0)
My VPS server uses linox OS.
You do write absolute route to php-cli command and artisan script to properly work:
/usr/local/php70/bin/php-cli /home/{username}/{path-to-app}/artisan schedule:run >> /dev/null 2>&1
I am using laravel 4.2. I have created command file for cron job and added it into artisan file. I tested it in command. Everything is working fine in localhost. In Cpanel server I gave command path like,
php /home/fridayburr/public_html/version1/artisan active:user 1>> /dev/null 2>&1
But cron job is not working.
This is how I did in my shared Hosting using CPANEL
Here CRON Task is set on UNIX, to run every minute.
Add the schedule call with appropriate time schedule.
laravel Schedule documentation
My Codeigniter Project Cron Job Not Working Correct
/usr/local/lib/php /home/{username}/public_html/index.php MyCron index
but my Cron Not work Correct
and call Default Home Controller
i need to call my MyCron Controller and index Function
So please help me
This could be because a couple of things. First of all, it could be because you have the wrong path for php. The path on my server is:
/usr/bin/php
You can find your path by typing:
whereis php
Second of all, it could be because you haven't installed the packages neccesary on your server. You need the package php cli
sudo apt-get install php5-cli
Lastly, your cron controller may contain errors, I recommend checking your log file, if you see any errors. For me, the crontab job that is working is:
0 10 * * * /usr/bin/php /var/www/<MY_PROJECT_NAME>/index.php Cron
So yes you can indeed use capitalized words when calling your controller.
Your controller should not be capitalised
/usr/local/lib/php /home/{username}/public_html/index.php mycron index
also index method should not be required as it is the default method.
id like to know :
Where Laravel php artisan serve command logs stored ?
How to automatically start php artisan serve when sever (Apache) starts ?
Laravel logs are stored at storage/logs
You don't need artisan serve, if you have Apache handling your HTTP traffic.
To the first question
Where Laravel php artisan serve command logs stored ?
Laravel server logs are stored in storage/logs folder ,which contains files for the server logs
To the second question
How to automatically start php artisan serve when sever (Apache) starts ?
If you need to automatically ,A very simple way to do this would be to use use laravel scheduling Artisan Commands using cron
Ensure cron is installed yum install vixie-cron (assuming you use centos). Start it with service crond start
Add laravel Schedule object vi /etc/crontab and add * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 ,to the cron schedule file .
Go to app/Console/Kernel.php file and add $schedule->command('foo')->withoutOverlapping(); where foo is the artisan command you would like to run in this case serve , so it should be $schedule->command('serve')->withoutOverlapping();
Restart cron deamon with service crond restart.
See this related question https://stackoverflow.com/a/34096590/1226748
I would definitely recommend NOT using artisan's server in production like EVER, it's for testing only. -- You would be WAY better off to use nginx as a reverse proxy and you can set whatever port you want that way, and have your angular app still connect to it.