how to set Log rotate in laravel? - php

Right now I'm using a single log file, but there is requirement to make it daily , but for the current date, the file name must be laravel.log
laravel-2020-08-30.log
laravel-2020-08-31.log
laravel-202-009-01.log -> the current date must be laravel.log
`
Is it possible to get the logs daily, but named like this?
laravel.log
While the older (up to a week) are named like this:
laravel-2020-08-30.log

You can try given solution for you problem.
Update your .env file.
LOG_CHANNEL=daily
then you can run following this command on your terminal inside project root directory.
php artisan config:clear && php artisan cache:clear && php artisan config:cache
Now you can check your storage folder inside logs directory with following name conversion.
For ex:
laravel-2020-09-01.log

Related

Failed to open stream: No such file or directory (.env file)

Running the command "php artisan key:generate" on the docker container it shows:
file_get_contents(/var/www/.env): Failed to open stream: No such file or directory
However the .env file exists. Do you know what can be the issue?
Found someone with the same problem (and solution) here
If, like me, you did have a .env file, you may find it has permissions that are too tight to allow your current user to write to it (and by implication the php artisan command your current user is attempting to run). I had changed all my Laravel files to be owned by www-data:www-data and made my current user a member of the www-data group, and was thus a little stumped by this error.
However, I soon realised that my .env file has the following permissions:
-rw-r--r--
...meaning the user which owns the file gets read-write, but the group and world can only read. Since my current user is a member of the group www-data, it can only read, not write.
(You can check your file permissions by doing $ ls -la)
If you have the same situation, you have two choices; loosen the file permissions on that file (with chmod) or use sudo to run your php artisan commands. I chose the latter, since this is a production server for me and I like the tight permissions.

laravel 7 artisan key:generate not working

when i run php artisan key:generate in cmd it's return
file_get_contents(/project/positiv/core/vendor/psy//.env): failed to open stream: No such file or directory
at
/project/positiv/core/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
{
file_put_contents($this->laravel->environmentFilePath(), preg_replace(
$this->keyReplacementPattern(),
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));
}
I am trying to generate APP_KEY!!!
At first generate APP_KEY with the command php artisan key:generate --show. It will print contents on your terminal which you can copy and paste wherever you want. In this case APP_KEY=value on your .env file.
Generated Key format will be something like base64:xxxxxxxxxxxxxxxxxxxxxxx.
It seems that you are trying to run artisan command outside the project.
Make sure your terminal is targeting the exact project you want to trigger

php artisan serve not generating url (localhost:8000) in right directory

I completed upgrades from laravel 5 to laravel 8.
But my php artisan serve is not working.
I mean when i type php artisan serve and type enter then we should get an output showing some localhost link.
But for me it is not doing that
C:\Users\kr php artisan serve
C:\Users\kr
go to the .env file and change localhost to 127.0.0.1

file_put_contents(C:\storage\framework\views/27f511f5644086daa68b2cf835bf49f5148aba43.php): failed to open stream: No such file or directory

so i keep getting this error on my live server but not on my local host, everything works normal on my localhost but when i deploy my website on online server it keep giving me this error
file_put_contents(C:\appname\storage\framework\views/27f511f5644086daa68b2cf835bf49f5148aba43.php): failed to open stream: No such file or directory
i tried php artisan config:cache but nothing really worked
I suppose your issue is due to the Laravel Configuration Caching.I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands like this:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
I hope this is helpful.
I'm going to guess that you have the wrong path being used, so try this to ensure that regardless of the server, you will have the right path:
$path = dirname(__FILE__);
file_put_contents($path.DIRECTORY_SEPARATOR.'27f511f5644086daa68b2cf835bf49f5148aba43.php');
This assumes that you are trying to write to the same folder as the code file that is running this.
You can also use the following to determine exactly what the path is on each server:
echo getcwd();
Looks like your storage/ directory is not writable. Laravel requires that directory to be writable.
If you're on linux/mac, run this
chmod 0755 storage/ -R
Hope that helps.
Try and use next command "php artisan cache:clear" will help you to clear cache for app

Cannot execute external PHP with Laravel artisan scheduler

I have an external PHP script, that is processing an XML array to insert, update or delete rows in a database. This script lies in the root of the project in a folder called scripts and I can run and execute it via terminal with no problems whatsoever and it updates the database accordingly:
php index.php
I have also set up a schedule in Laravel (using October CMS syntax)
public function registerSchedule($schedule)
{
$schedule->exec(public_path() . '/script/index.php')->everyMinute();
}
This however is doing nothing. I tried manually running the schedule with artisan in command line by:
php artisan schedule:run
And the output is
Running scheduled command: /Users/x/x/x/x/scripts/index.php > '/dev/null' 2>&1 &
Nothing happens in the database tho.
Did you try to generate a new key?
php artisan generate:key

Categories