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
Related
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
I'm using a Mac. Can not execute the command
php artisan cache:clear
I get in return:
Failed to clear cache. Make sure you have the proper permissions.
This is for Laravel. Any ideas how to fix this?
create storage/framework/cache/data directory manually.
This could be one of several things(need more information to narrow it down):
No cache files/records exist.(Updated to reflect your latest comments)
If you are running a webserver (apache or ngix) as a different user, then you won't have permissions to the files as yourself.
If you are using a cache driver other than file, like redis or database, make sure the credentials provided are correct.
There could be a bug in the version of Laravel you are using; this would be unlikely.
Expansion on points 1 and 2:
This is normal behavior. If you have opened pages expecting them to be cached and they are not, split the page and utilize #include directives splitting out the dynamic and static elements of the page into separate blade files.
I like to add my user to the same group as the web server's group(www). Then change the group for all of the files to www, with group read permissions, and write permissions only on the bootstrap/cache and storage directories.
I think it might possibly be a bug with the latest version of Laravel, however unlikely it may seem. I started a new project today and installed a fresh copy of Laravel 5.7 and it seems to cause the error above. However, if I use 5.6 then the error does not appear.
I have bee using Symfony for a while now, and recently ran into an issue where the app/console cache:clear didn't want to clear the cache.
I then discovered that you can manually remove the app/cache directory to clear the cache.
So aside from doing the app/cache folder, what does cache:clear actually do? Why would i keep using it rather than removing the cache folder?
It also does the cache warmup (at least in version 3.1, which I'm currently using) unless you tell it not to do so with --no-warmup.
It's also easier and faster to run commands in IDEs like PHPStorm then manually doing things such as removing files.
Basically you can just remove cache directory if you prefer such way. Cache warmup will be performed at first Symfony request is needed.
You can also attach event to clear some of your custom cache.
This mean if you remove cache directory, you're not sure to clear custom cache handling
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'm using LAMP with CodeIgniter for one of my projects; version controlled by SVN. Every time I execute svn export file:///svnrepo/project/trunk/www . --force when in the www directory and then reload the web page, it goes blank.
The website only shows up after I do a service httpd restart (Using CentOS 5).
I want to be able to execute the svn export using a Phing build script in the future and I don't want to have to get root privileges and restart apache every time when I do a build.
Is what I'm experience a common problem? How do I solve it without restarting apache?
Edit:
It seems someone has had this problem before: http://codeigniter.com/forums/viewthread/181642/
Ok I got it.SVN maintains a files last modified time which throws off the APC cache. So to solve it we update the last modified time of all the files after we run an SVN export. Here is my final script:
#!/bin/sh
svn export --force file:///home/steve/repo/exmaple/trunk \
/home/steve/public_html/example.com/public/
find /home/steve/public_html/exmaple.com/public | xargs touch
You can find more details here.
An alternative solution would be to set apc.stat=0 (reference) in the apc.ini, and then use apc_clear_cache() (reference) to force the removal of the opcode cache.
What's awesome about this solution is that when apc.stat is set to 0, it disables the check on each request to determine if the file has been modified. This results in a huge performance boost.
Additionally, using apc_clear_cache() to clear the APC cache tends to result in a cleaner build. I've run into wonky race conditions where certain files will get built out that have dependencies on others that have not yet been built out. This results in a spat of FATAL errors. The only caveat here is that apc_clear_cache() needs to be run via apache, so you'll need to implement a wgetor something similar for this.