How to disable cache in Laravel 8 for localserver? - php

How to disable cache in Laravel 8 for localserver? Its creating too much cache files. Its taking too much time to reflect changes.

To disable the cache you have to add the following to your config/cache.php file.
'stores' => [
//...
'none' => [
'driver' => 'null',
],
],
Now you have to change your CACHE_DRIVER value to none in your .env file and your cache is disabled.

You can do multiple things like:
CACHE_DRIVER=none
CACHE_EXPIRE=-1
and a command to clear view cache:
php artisan view:clear

In your .env file, set:
CACHE_DRIVER=array
Arrays are not persisted between requests.

Related

laravel config:cache creates different cache file between first run and afterwards

I just run into curious behavior of laravel config:cache.
When I create a .env file with
APP_ENV=production
THIS_IS_TEST_1=1
THIS_IS_TEST_3=1
(not important lines are snipped, the same goes for the others.)
and I create .env.production like
APP_ENV=production
THIS_IS_TEST_1=2
THIS_IS_TEST_2=1
then I add lines to read .env value in config/app.php
'this_is_test_1' => env('THIS_IS_TEST_1', -1),
'this_is_test_2' => env('THIS_IS_TEST_2', -1),
'this_is_test_3' => env('THIS_IS_TEST_3', -1),
After that, I've typed command ./artisan config:cache. It generates cache file as bootstrap/cache/config.php with values below.
'this_is_test_1' => '2',
'this_is_test_2' => '1',
'this_is_test_3' => '1',
So, at the first run of ./artisan config:cache generates cache file with both .env and .env.production. And also values in .env overwritten by values in .env.production.
And then, this is most curious part, I've run ./artisan config:cache following the first run generates cache file with values below.
'this_is_test_1' => '1',
'this_is_test_2' => -1,
'this_is_test_3' => '1',
This cache looks like based on .env and not on .env.production. After second run, ./artisan config:cache generates cache only with .env.
When I run config:clear and clear the cache file, then ./artisan config:cache generates config cache as same as first attempt.
'this_is_test_1' => '2',
'this_is_test_2' => '1',
'this_is_test_3' => '1',
Is this a normal and expected behavior of laravel?
I've placed entire example on github.
https://github.com/kent013/laravel-config-example
This example project is generated with composer create-project laravel/laravel example-app and just changed few lines to regenerate the behavior.
Any helps are appreciated. Thanks.
So you saying it is ignoring .env.production in second run? It could be because the both files have same APP_ENV=production. May be you should try changing APP_ENV in the .env file.

Laravel database still use old name after .env changed

Edit:
php artisan config:cache work nice, but now I got other problem.
the URL giving me Error 500
I upload a project to a new subdomain area after I changed .env file
when I open URL I still got an error with the old database and user
I tried to check online with the .env file but - I don't know where he stored this database, I tried to see where is this name with ctrl+f but - nothing found
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=faceterc_hot
DB_USERNAME=faceterc_hot
DB_PASSWORD=testpro
I expect to get the same error maybe but not with the old database name.
and this gives me a indicate that maybe the file or something not changed or he using the other details from I don't know where
Good, practice for, If you change in a .env file first restart the server using below command.
php artisan serve
then after run below more command for clear old cache and config.
composer dump-autoload
php artisan config:cache
php artisan config:clear
You can simply do a
php artisan config:cache
In case you are on a shared hosting, you can change the values in config/database.php to only use the set values in your .env. Setting it like this will make sure, it only use the .env values.
mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
php artisan config:clear Solve the problem with DATABASE error
just ran :
php artisan config:clear
with ssh at the main folder.
Just execute
php artisan config:cache
as the laravel cache's the environment files rather than accessing the data from it on every request.
It's always a good practice to run these couple of commands when you change any environment related variable:
php artisan config:clear
php artisan cache:clear
Execute these commands:
php artisan config:cache
php artisan route:cache
php artisan optimize
That will clear your env cache and it should do.

Modifying public disk url - Laravel 5.8

I'm trying to achieve two things within my Laravel 5.8 project:
First of all, add the next variable on my .env file:
FILESYSTEM_DRIVER=public
And finally, modify my public disk url from this:
'url' => env('APP_URL').'/storage',
To this:
'url' => env('APP_URL').'/api/storage',
Either way, it doesn't work. What am I doing wrong? Is it the .env variable or I can't do such thing as modify the disk url?
Yes you can. To modify the default file system, set the FILESYSTEM_DRIVER in your .env file:
.env
FILESYSTEM_DRIVER=public
Then in your config/filesystems.php, to modify the url do this:
config/filesystems.php
'disks' => [
...
'public' => [
...
'url' => env('APP_URL').'/api/storage',
...
],
...
],
Do not forget to clear your config cache after doing this changes:
php artisan config:clear

Laravel Scout production error with TNTSearch driver

Searching using the TNTSearch driver works in a Homestead environment however on production it returns error: the below error,
Symfony\Component\Debug\Exception\FatalThrowableError: Class
'AlgoliaSearch\Version' not found on
vendor/laravel/scout/src/EngineManager.php:31
However my .env has SCOUT_DRIVER=tntsearch and the config file scout.php has:
'driver' => env('SCOUT_DRIVER', 'tntsearch'),
'tntsearch' => [
'storage' => storage_path(),
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
'asYouType' => false,
'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),
]
The problem is that I am not using Algolia search and my composer file has Scout and TNTSearch driver. The search works in my local Homestead environment just not on the production server.
Confirm that SCOUT_DRIVER=tntsearch has been added to your .env file.
For me personally, I had added SCOUT_DRIVER=tntsearch to my local .env file, but not my .env file for the environment with the issue. Don't forget to run php artisan config:clear after adding the env var.
Thanks to #m33bo for pointing me in the right direction!
I worked it out, I had uploaded my project but for some reason the .index file that is needed sync'd but did not work. If this happens to you on live make sure you Git or SVN or whatever the index or run php artisan scout:import App\\Your\\Model

spatie/laravel-backup "mysqldump" doesn't recognized when I run it through Artisan class

I'm using spatie/laravel-backup in a WAMP localhost.
It works fine when I type manually in the windows cmd:
php artisan backup:run
But when I try to run the backup using the laravel Artisan class:
Artisan::call('backup:run');
It throw an error:
'mysqldump' not recognized ...
In the laravel mysql config I've also specified the path to the dumper:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:/wamp/wamp64/bin/mysql/mysql5.7.9/bin',
],
],
How can i fix that?
EDIT
Probably it's just support "bug" for windows (finded out thanks Loek's answer), as the author says, so can I run a backup in a controller without a command safely? maybe with something like:
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
BackupJobFactory::createFromArray(config('laravel-backup'))->run();
As the command itself.
I believe it's the forward slashes. Try this:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:\\wamp\\wamp64\\bin\\mysql\\mysql5.7.9\\bin',
],
],
EDIT
Support for Windows is wonky at best, with multiple "This package doesn't support Windows" comments from the creators on GitHub issues. This one is the latest: https://github.com/spatie/laravel-backup/issues/311
It could also be a permission problem. Executing from the command line is probably happening from another user than executing from the web server, so Windows is denying access to mysqldump.
2nd edit
As long as you make sure the controller only gets called when it needs to be, I don't see why this wouldn't work!

Categories