Refresh Laravel environment variables on shared hosting - laravel

I implemented my website on a shared hosting environment. Works perfect!
But now I changed functionality and want to use 'queues'. In my earlier instance the environment variable 'queue_driver' contained the default value 'sync', and now I changed that to 'database' in the environment file.
Question is now: how to activate this new setting?
I already tried to clear cache and config, but it does not change anything?
Can I enforce refreshment?

Use php artisan config:clear to clear the cached config files.
Maybe also follow up with composer dumpautoload

Related

Why do I need to run php artisan optimize after adding a route

If I do not run php artisan optimize and I go to a new route in the browser I get Page not found
Everytime you push a new version of your project to production it is recommended to run php artisan route:cache.
On dev environment it is recommended to have no cache and ensure that by running php artisan route:clear.
When you do
php artisan route:cache
A file like bootstrap\cache\routes-v7.php gets created holding all your routes from routes\*.php which are contained in Route methods that weight some calculation cost on your server each time you send a request to figure what to do for the current route.
Quoting from bootstrap\cache\routes-v7.php comments:
This allows us to instantaneously load the entire route map into the router.
Important:
This cache file doesn't get auto updates and doesn't exist in a fresh project.
This cache takes precedence over routes\*.php files.
The bootstrap\cache folder is ignored by default by git.
Here is an extensive great article for more details https://voltagead.com/laravel-route-caching-for-improved-performance/
Note that the optimize command was removed from the framework then added back.

Installing (Laravel) Dusk on Lumen

I am building a self-consuming Lumen API that has a single Lumen view (which serves the HTML to which the React app is appended).
I was able to install Dusk with
composer require --dev laravel/dusk
which seemed successful.
However, when I run
php artisan dusk:install
I get
There are no commands defined in the "dusk" namespace.
I know Lumen has a stripped-down php artisan. But, wondering if I can add the commands to the "dusk" namespace, or if anyone has successfully used Dusk with Lumen.
Thanks to Jared's answer,
I found I had to manually register Dusk's service provider before I could run php artisan dusk:install. The current Laravel documentation doesn't mention registering it, but it seems like it might have to be done for Lumen.
So all I had to do was add
if (app()->environment('local')) {
$app->register(Laravel\Dusk\DuskServiceProvider::class);
}
to /bootstrap/app.php below the Register Service Providers comment.
As Jared mentions, you don't want it to register in production environments so I stuck it in a conditional.
Once added, I was able to run php artisan dusk:install and got Dusk scaffolding installed successfully.
Be sure you have the .env file setup correctly.
The APP_ENV should be set to local or testing for dusk to work.
Also check if it's was correctly installed by checking the Register Service Providers in your bootstrap/app.php file. Dusk should be listed there.
If you are manually registering Dusk's service provider, you should never register it in your production environment, as doing so could lead to arbitrary users being able to authenticate with your application.

Laravel artisan command from controller

I update my .env file using a function in my controller.
After I save the settings I need to update, I call Artisan::call('config:cache') to clear the cache of my site's configuration.
Everything works fine on localhost, but when I try to clear config cache on production, it doesn't work. (No warnings or errors.)
I even tried with --no-interaction option attached to this CLI command.
Did anyone have this problem and know what causes it?
check into the PHP security settings and make sure you can run these exec,passthru,shell_exec functions in your server.

How to stop Laravel 5 from caching configurations?

It is written in Laravel 5 documentation that php artisan config:cache stores all the app configuration into one single file which makes the application load faster.
I want to know two things:
The first thing is, how to force Laravel to stop caching my app configurations? For example, I want Laravel to read the name of my database and the password from the .env file or from the database.php configuration file, not from the cached data.
The second thing is, where does Laravel store this cached configuration file, so that I can delete it when needed? I know there is an Artisan command for that, which is php artisan config:clear, but I want to know where the file stored.
You can't stop the caching of config files since it doesn't happen automatically. The only thing you need to do, is not call config:cache.
The file itself can be found in bootstrap/cache/config.php.
Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.
As per the post here: https://github.com/laravel/framework/issues/2501
"Change cache driver to array for the local environment."
For me this involves adding CACHE_DRIVER=array to my .env file. This is then picked up by my config/cache.php file which includes the line:
'default' => env('CACHE_DRIVER', 'file'),
Obviously you could change it directly in the config/cache.php but I'd prefer to use the .env file so I can disable it for development sites and enable for production.

Laravel, codesleeve asset-pipeline not working

I am trying to get codesleeve asset-pipeline to work on my site. After wasting a full day, I finally got it working yesterday on my local development server. I have now uploaded the project to see if everything works on the live server. Guess what- it doesn't. I am guessing the problem is to do with the environment setting, ie:
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
So, I have changed that to my machine name when on my local server, which, as I say, I have working. So on the live server, what should this be? "localhost"? I have tried adding another array key for 'live' with my live server's IP address and domain name, as per this answer: http://tinyurl.com/pg6hwum Nothing works.
Also, according to the tutorials I am following:
When you are in the local environment, you will notice that all of your asset files will be included individually ... Once you are in the production environment, all of your assets will be concatenated into one.
That doesn't seem to be the case for me either, as pipeline seems to be half-working, ie. it is concatenating my js and css files, but somehow messing them up.
I'd really appreciate some pointers, as I have wasted a colossal amount of time with this thing now. Thanks.
First set your environment settings on your bootstrap/start.php file into something like this:
$env = $app->detectEnvironment(array(
'local' => array('http://localhost', '*.local', 'http://local.sitename'),
'development' => array('http://dev.sitename.com'),
'production' => array('http://www.sitename.com', 'http://sitename.com'),
));
Second you need to check what enviroment does your laravel is running to check if your environment setup is working properly. By doing this:
App::environment()
So by doing that..you should have idea now what is causing the problem on codesleeve asset-pipeline.
note: see the documentation about environment for more details here
Asset pipeline will out of the box behave differently when on production compared to another environment (like local). I have put in a proposal to document some of these pain points and troubleshooting for new comers.
If you are using the most current version then there are two big behavior changes when switching environments:
caching - production assets are cached. This means once you load a page you will be stuck with those assets until you do
$> php artisan assets:clean
This is why you should set your environment to local when developing.
minification - assets are minified on production only. This can cause issues though because the minifiers sometimes break on code. There are some workarounds you can do to fix this. Something I normally do when having issues with a certain file (say Twitter Bootstrap) is use the .min.css extension which is then skipped by the minifier and written out as-is.
Note that this behavior is out of the box and can easily be modified by editing your configuration.
$> php artisan config:publish codesleeve/asset-pipeline
Then edit your file app/config/packages/codesleeve/asset-pipeline/config.php. For more information on these options visit the documentation here.
Hope this helps.

Resources