Whenever I try to update my project in Artisan, the commands I run work, but some of them take a very long time to execute.
For instance, here is a section from my api.php:
Route::apiResource('questions', 'QuestionController');
php artisan serve works in my terminal, and this route is accessible.
But when I delete this questions route, I expect the route host/questions to become inaccessible. However for about a minute after running the command, I can still access the route through the normal URL as if it wasn't deleted.
So what exactly is going on here? Is this caused by caching, and if so, how can I prevent this?
I want a leave-reload thing for my Laravel project.
I'm recompiling my files using ctrl+c, php artisan serve every time, and using Laravel 5.8 with PHP 7.3.7.
This is probably because Opcache keeps a copy of the files for a moment.
Try to disable opcahe and try again.
Check php.ini and see if opcache.enable is on "1", if so, change it to 0, and restart php artisan serve
Related
When I develop a Laravel application I used to clear cache after making any changes to routes\web.php or routes\api.php. Recently I was working on a project for a fellow and found out that the project does not need clearing cache every time I make a change in any of the files I have mentioned.
So I want to know what is the problem with the autoloader or what exactly is the general problem?
When you use commands like
php artisan optimize
php artisan route:cache
your route files(under routes/) are being parsed and cached. Now, next requests will be routed from cached routes, not from routes/*.php.
If you have used above commands, after making changes to route php files, you should re-cache them, or use
php artisan route:clear
to remove the cache. Then, next requests will be routed by routes/*php files.
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.
I'm using Laravel 5.4 on Windows 7 and Xampp 3.2.2. A few days ago Laravel started ignoring the changes I was making to the .env file. I couldn't find the solution so I reinstalled Laravel in a different directory and imported my app folder.
Now Laravel just stopped responding to the changes I am making to some PHP files. I added a function to the /vendor/illuminate/support/helpers.php but I could not access it in the view. I deleted the content of the whole file and I could still access the function previously declared in it.
I created a helpers file as instructed here but that too is being ignored.
Any changes to any views is immediately effected and php artisan cache:clear is not doing anything.
How is this happening? Does it even make sense?
Laravel caches config values to improve performance.
You need to run either (recommended)
php artisan config:cache
which will cache the new values you have, or
php artisan config:clear
which will turn off caching. I've had some experience with this causing errors though.
I know it might sound rather stupid, but have you remembered to restart the server because you've edited the .env file?
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.
I am using Laravel's file caching system (at least temporarily) to cache numerous smaller, mainly static objects from the database. However, if I use artisan to run some functions (which add/call from the cache) and then try to load a webpage, I get permission errors while trying to access the cache. Same error when done the other way around (view web page and then run artisan).
This is because the cache is owned by me when I run an artisan command, but is owned by apache when run through the webpage.
I have thought of 2 solutions. One, delete all the cache at the beginning and end of all artisan calls (not ideal, loses most of the performance boosts). Or, run all my artisan commands as the apache user (not convenient, and maybe not even possible).
Is there a way to modify the permissions automatically of Laravel's file caching? Or set artisan's caching to use the apache user maybe?
Not the most elegant solution, but I ended up just removing caching from my artisan commands. These were just background tasks that did not need the same speed boost as the front end does.
You can try to chmod the storage folder to 0777. You can do this using your command line.
$ chmod --help