Stuck in the world of cache in laravel - php

I have been working in an application for month now.
But after running this command
php artisan optimize
I am stuck with the world of laravel cache,
I can't do or test anything locally unless I always have to
clear the cache then run optimize again and again.
sometimes it does work and other times it looks for old code which doesn't even exists. it has stopped my ability to work on and test my code.
I haven't tested my application on production server.

Run php artisan optimize:clear to undo it and don't run php artisan optimize in your local environment.
Only enable caches on your "live" environment and never locally while developing.
This will prevent any weirdness when developing and making sure you are looking at the effects of the code you just written instead of some cached code.

Related

WSL2 Ubuntu 20.04, Docker and Laravel launching local host won't display on browser

I have a strange one here, I have been learning Laravel with Laracasts from scratch 8 for the last couple of weeks, everything in my environment (Ubuntu WSL2, Docker and Laravel 8) was running smooth all week with no issue. I returned to work this morning and following the same boot up I always do, now any browser I use can't open the local host port that I launch from php artisan serve.
The CLI tells me that the development server is active but the browser won't connect. I've tried changing it across different networks, dropped firewalls and cleared caches. I've checked logs and nothing gives an indication of a problem. Usually when I run the command php artisan serve --host=127.0.0.1 --port=8080&
the ampersand keeps it alive and every refresh or connection is returned to the CLI, it's like artisan serve has stalled?
I think I found a solution and if somebody comes across this and can explain why it would be of great help in the future.
https://stackoverflow.com/a/40167414/2128089
composer dump-autoload
php artisan clear-compiled
composer clear-cache
This answer gave me some commands to run, which were the last I ran before a computer shutdown, once I re-ran my usual boot up I got all systems go
As expected:
I don't know if this is why it worked but it's working..

Laravel PHP run php artisan serve automatically if something changes

I am using laravel for a php webproject.
Yesterday I noticed an issue:
Everytime I make changes f.e. in the controller files I need to rerun php artisan serve, which consumes a lot of time (close CMD, open it again and type php artisan serve)
I am trying to find a way, so this command will automatically rerun when I test my application on localhost.
I could probably write a script or something with Python, which will automatically open CMD and execute php artisan serve whenever I click f.e. CTRL + F5, but that feels very hacky, is there a cleaner solution?
I also found a guide on how to edit the hosts file in system32 folder and the httpd-vhosts.conf in the apache folder, but after doing all steps, if I try to reach my application I get "It works" instead, which is simply an indicator for a successfull apache installation.
You should avoid php artisan serve cause it's just a shortcut to run your Laravel project. For a better development environment, you should use Laravel Homestead which offers a complete solution.

Deploying Laravel 5.4 to Shared Hosting

I've got a real head-scratcher for you! I've been working on a Laravel 5.4 application for quite some time now and up until yesterday I had been able to:
develop on my local machine [still works flawlessly],
push my changes to my BitBucket repo [still okay here],
and would subsequently pull those changes to my shared hosting server (RedHat) [still running smoothly],
I then run my dependency managers (npm and composer) to get the project in place and functional
there is some matter with clearing various caches:
php artisan view:clear
php artisan route:clear
php artisan cache:clear
composer dump-autoload
and finally move my '/public' folder to the web root and update index.php to point back to the 'bootstrap/autoload.php' in main project structure,
I am aware there is likely another or several steps I am missing, but I am unsure what they are...
All that being said, I've attempted to deploy a number of applications using Laravel lately and I always seem to run into the same issue come time to deploy an application to production. I've read 30+ tutorials on the matter and nothing seems to explain the issue why my site isn't working any more.
I've checked the error log file maintained by Apache, it's empty.
Was wondering if it's a permissions issue, doesn't seem to be the case (all folders set to 775 and files set to 664 as specified by various sources and owned by serverName:userName)
Browser console simply shows a 500 server error.
All I see if "Whoops, looks like something went wrong." twice.
There must be some way to show better error details (config debug setting already set to true)
Any suggestions at this point would be beneficial to send me looking in the right direction!
======= UPDATES =======
For the sake of thoroughness, and that this save others from severe headaches, I'll be posting actions taken here.
Following tutorial mentioned by #user123456 (permissions applies)
Generate new key for application
Run php artisan config:clear
Off to the races, answer to come!
You need to ensure you have a working .env file.
Once done, run php artisan key:generate to create a key for your application after which you should clear your application's cache as follows php artisan config:clear
I would never recommend using shared hosting for Laravel application. You will face lots of issues for permissions, composer and external dependencies. Instead, you can use cloud servers like DigitalOcean, Linode, vultr and deploy laravel application on them. If you don't know about linux and creating Stacks you can use Cloudways to deploy laravel.
https://dev.to/rizwan_saquib/deploy-laravel-application-on-cloud-easily-with-cloudways

PhpStorm takes FOREVER to show saved changes during 'php artisan serve'. Any "fix"?

I am getting really irritated by how PhpStorm does things.
I'm serving the application doing php artisan serve and then I'm editing the files within PhpStorm IDE. I made it so that I have to manually save it, because I just hate the autosave features of PhpStorm.
Anyways, whenever I make changes to a webpage and save, it takes AGES (okay maybe like 15-30 seconds. But that's a relatively long duration) for it to actually show up on my local server when viewing on Chrome (And it can't be a caching issue since I use CTRL+F5 to clear the cache).
Like I literally can stop php artisan serve and then restart php artisan serve to see the changes before it updates by itself...
Why is this so? What IDE do you recommend me using, if this is something I have to live with using PhpStorm?
(I'm editing a Laravel Framework app, on a Bitnami WAMPstack.)

Whats the point of running Laravel with the command 'php artisan serve'?

I dont seem to understand why we need to run a Laravel app with php artisan serve vs just running it with Apache or nginx. I know that under development, we use artisan to fire up the site and after deployment to a server, you use the webserver to load up the site.
Whats the use of running the app in artisan in the first place?
The serve command is just a shortcut for the PHP Built-in Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.
One advantage of using php artisan serve over a typical webserver during development is you can use Psysh as a debugger (Laravel Tinker) to set a breakpoint.
For example, at the line of code I want to break at I type:
eval(\Psy\sh());
Then I hit the page that will run that section of code and when it gets to that line it will break into a Psy Shell repl (in the commandline window where I started php artisan serve). Then I can inspect variables, etc. at that point of execution. It's very useful for debugging. As far as I know, you can't do this running Apache/Nginx. It has to be with artisan serve (or running automated tests).
More info here:
https://tighten.co/blog/supercharge-your-laravel-tinker-workflow
http://psysh.org/
Purpose: The purpose of using Php artisan serve (PHP builtin server) is just for testing and easy starting your project it should not be used in real website deployment.
Asset Not working: Always put your index file in public it's the beauty and security of Laravel framework and your assets will always working. if you are bore to use your custom URL like C:/wamp/www/pym/server.php then use Virtual host locally but don't but don't put your index outside the Public folder.
if you really want to use index at your Root directory then you should customize your all asset() and url() helper functions and should put your exact url Example asset('/login') should be changed to asset('localhost/yourprojectroot/login').
php artisan serve --host your_server_ip --port 8000
copy that http://your_server_ip:8000 and run it into the browser
Aside from the best answer here.
You can see the logs directly where you execute the php artisan serve, so useful in debugging.
Well, was looking for the same answer but couldn't find any that is satisfying so , if your also unsatisfied just like me try running the link returned when you run
php artisan serve
it returns
Laravel development server started: <http://127.0.0.1:8000>
copy that /http://127.0.0.1:8000 and run it into the browser , guess what it returns );the page that u first got when you installed laravel for the first time or i guess it will return the page in the routes folder which was set as /home directory or file(default home page).
In brief:
php artisan serve
starts the serve,forexample its like when your going to drive a car and you start the engine before driving whereby you can start the engine and drive at the same time ,its not neccessary to do so but depends.So to me that's php artisan serve CLI.

Categories