Cannot delete Laravel Application cache from deployment script - php

I am trying to setup a deployment script for my Laravel 5 app to use with CodeShip but I am having issues with clearing the application cache during the deployment.
By running
php artisan cache:clear
it does not give any errors and says the cache has been cleared but it hasnt, then when I ssh into the box and try to delete the cache manually it says permission is denied, so I need to use sudo which is not ideal as Id like to have this all to run without my intervention. I know this is a permissions issue but I cannot work out a way around it.
Is there a way I can do this or maybe a slightly different method?

You shouldn't delete cache manually. Try to run these commands:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
composer dump-autoload

Try php artisan config:cache
This will do it all for you.
Hope this helps!

Related

Getting Error 500 after composer update from ssh

I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
run composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve

Laravel Reflection Exception Class Does Not Exist

I was trying to troubleshoot a Laravel issue by clearing cache and dump auto load and updating composer.json file and now when I navigate to my server I get all of these errors. The error before was boostrap cache had wrong permissios so I did sudo chmod -R 775 bootstrap/cache to fix that issue but now I have a bunch of other errors.
UPDATE: route list is as follows: photo
This command worked on my issue:
php artisan config:cache
In the Laravel doc it says that laravel by default is configured to use file cache driver which stores cached objects in filesystem, so it is necessary to recache filesystem. this is because after clearing the cache laravel doesn't know of which view to fetch from cache although you have cleared it. so after config:cache it tells to laravel to recache the new views and to available it to show. Hope it will help.
Change mode to 777 and after that run commands: php artisan config:clear && php artisan config:cache && php artisan cache:clear. Then if bootstrap/cache/config.php was not deleted then delete it also and try again.
It will work fine.

How to recompile Laravel's Controller

I have a Laravel app running behind an Apache2/Ubuntu-16.04. I have to change a little code line in my controllers ( .i.e. a typo mistake in
laravel_project/app/Http/Controller/MyController.php). But when I reload the webpage using the browser, it still doesn't update with my fixed version. I tried some cleanup commands:
php artisan config:cache
php artisan route:cache
php artisan list
php artisan clear-compiled
and also restart apache2 but it still doesn't work. Can you please help me. Thanks.
I had the same issue, its was because of routes cache
I resolved it by:
php artisan route:clear

php artisan serve get cached or does not react while updating code in Laravel 5.5. After a restart, it works again each time

My IDE is phpstorm and running on WAMP Server. While coding, it does not show the expected response, always returns the previously requested response (In postman). Each time, I need to close 'php artisan serve' with CTRL+C and then run again to get the expected response.
I tried changing IDE, changing port but it does not work. Of course, I tired to save manually ( CTRL+S) but the problem persists.
I also tried the following commands:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
composer dump
But the problem still persists.
The issue might be the composer command. Please, have a look on my setup in the Makefile:
run:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
composer.phar dump-autoload -o
php artisan serve
And it's ready to go with a Laravel's "clean build".
Can you try with a diferent request tool, like doing a GET on your browser?
Or just create a new endpoint to test that. This way you make sure that changes are being saved.
I recommend you make tests to see if:
the problem is on your postman (a cache maybe?);
the problem is that your code isn't being saved;
the problem is on your local server (a persistent cache?);
My tip is: Try to eliminate the possible causes and you should achieve an answer.
Let´s try to make sure about above items and if them are ok, we check possible another ones.

Laravel 5.3 - Clear config cache in shared hosting

Currently I'm working on small project that require me to host my laravel app on shared hosting (please ignore the reason why I didn't use VPS to host my laravel project) and this hosting provider disable escapeshellarg() for security reason so I can't use php artisan config:cache to clear config cache.
Is there any workaround for this?
config:clear command just deletes bootstrap/cache/config.php file, so just delete this file manually.
You can call artisan commands programmatically
Artisan::call('config:clear');
This can be helpful in setups where the PHP user has a different set of permissions than the FTP user (so files created by PHP cannot be deleted via FTP)
Try also
for command line
php artisan config:cache
using artisan commands
\Artisan::call('config:clear');
https://www.tutsmake.com/laravel-clear-cache-using-artisan-command-cli/
try this command for clear all cached data at once.
php artisan optimize:clear
Here it is nice tiny library for shared hosting and typing clear bunch of clear commands one by one..
simply just install it once, and clear all caching issues in laravel with just one command.
Laracake
This is very handy
composer require laracake/clearall --dev
After installation
php artisan laracake:clear
This is how I restart queue server on live
## Restart redis and terminate curent jobs
php artisan config:clear ## clear config
sudo -i
cd /var/www/html
php artisan horizon:terminate ## need to be sudo , else throw permission error
php artisan queue:restart
exit
For Laravel > 7 because Laravel 5 is deprecated and the answers are not good enough.
I read all the answers but none of them contain optimize:clear so I want to write my answer for future users.
optimize:clear is the most powerful command to clean all the caches
in Laravel >= 7 you have this command for clearing all the caches
Command:
php artisan optimize:clear
It will clear: Compiled views, Application cache, Route cache, Configuration cache, Compiled services and packages.
It is not harmful at all. and it won't affect any single line of your codes. it just will clear all your cached files.
after running this command you will see:
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!

Categories