How to fix mpdf temporary files directory writable issue? - laravel

I'm getting this error in my laravel application.
Mpdf \ MpdfException (E_ERROR)
Temporary files directory "/var/www/html/../temp/" is not writable
Please anybody tell me the solution to fix this issue.

I fixed it like so:
$mpdf = New \Mpdf\Mpdf(['tempDir'=>storage_path('tempdir')]);
storage_path('tempdir') is the laravel-managed temporary directory.

I solved my issue by specifying tempDir to a usable temp directory
In config/pdf.php
<?php
return [
'mode' => 'utf-8',
'format' => 'A4',
'author' => '',
'subject' => '',
'keywords' => '',
'creator' => 'Laravel Pdf',
'display_mode' => 'fullpage',
'tempDir' => base_path('storage/app/mpdf'),
'pdf_a' => false,
'pdf_a_auto' => false,
'icc_profile_path' => ''
];
if you are not found config/pdf.php then you should publish package's config file to your config directory by using following command:
php artisan vendor:publish

If you are using docker, and having trouble to give the permissions make sure to enter in the docker container with root user using the follow command:
docker container exec -u 0 -it yourContainer bash
From this answer: Root password inside a Docker container

go to the directory "/var/www/html/../temp/" and check if it exists.
if it does not exists then create it.
if it exists give the necessary permission to it (usually 777 depends on your environment)

Related

Deploy to multiple servers with different project roots using Laravel Envoy

When deploying to multiple servers using Laravel Envoy, how can you specify the project root per server?. The example provided in the documentation assumes that the project root is the same path for both servers.
Assume web-1 has project root as /var/html/www and web-2 has project root as /var/foo/bar. How can I access the different server's project root at runtime?
There are different ways to use Laravel Envoy for what you want to achieve. For example, based on your description, something like the following would work in your Envoy.blade.php file after running envoy run deploy.
#servers(['web-1' => '127.0.0.1', 'web-2' => '127.0.0.1'])
#setup
function logMessage($message) {
return "echo '\033[32m" .$message. "\033[0m';\n";
}
#endsetup
#story('deploy')
deploy-web-1
deploy-web-2
#endstory
#task('deploy-web-1', ['on' => ['web-1']])
cd /Users/Shared
{{ logMessage('🚀 Task complete for web-1') }}
#endtask
#task('deploy-web-2', ['on' => ['web-2']])
cd /Users/khill
{{ logMessage('🚀 Task complete for web-2') }}
#endtask
you have to try this
$webServerIps = [
'web-1' => 'xxx.xxx.xxx.xxx',
'web-2' => 'xxx.xxx.xxx.xxx',
];
#servers(array_merge($webServerIps, ['persistent' => 'xxx.xxx.xxx.xxx', 'worker'
=> 'xxx.xxx.xxx.xxx', 'local' => '127.0.0.1']))
i hope you got your solution .
also you can follow this link for more help

Laravel php artisan produces error

I have integrated and working in a Laravel 5.4 project. I was actually configure this correctly and php artisan command was working perfectly before.But in between the development time(I have implemented the schedule task using laravel and not sure after that issue appear) it produces m error on php artisan commands. Can anybody help me on this.
The following is the error log for the command for any artisan command
PHP Fatal error: Uncaught
Symfony\Component\Debug\Exception\FatalThrowableError: Type error:
Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct()
must be an instance of Illuminate\Http\Request, null given, called in
/var/www/html/project/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php
on line 60 in
/var/www/html/project/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:103
Stack trace:
#0 /var/www/html/projrct/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(60):
Illuminate\Routing\UrlGenerator->__construct(Object(Illuminate\Routing\RouteCollection),
NULL)
#1 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(290):
Illuminate\Routing\RoutingServiceProvider->Illuminate\Routing{closure}(Object(Illuminate\Foundation\Application))
#2 /var/www/html/project/vendor/laravel/framework/src/Illuminate/Container/Container.php(746):
Illuminate\Container\Container->Illuminate\Container{closur in
/var/www/html/project/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php
on line 103
Please make sure that you are not using any url() or asset() or other helpers functions inside your configuration files
I my case url() helper function in my filesystem.php is causing the issue. I removed it and every thing works fine.
Another alternative solution to commenting out the url() and asset() calls could be to check the environment at run time:
return [
'URL' => app()->runningInConsole() ? '' : url(''),
...
];
If Really Need The Function To Be Inside Your Config, You Could use PHP_SAPI
To Check Weather The App Is Running HTTP or CLI,
'redirect' => PHP_SAPI === 'cli' ? false : url('synchronise')
I figured out the problem, when you are running any artisan command you should avoid using helper functions in any of your config files. Just comment those and try to run artisan command after running that uncomment your config files.
//in config/'any_file.php'
return [
'name' => 'Larvel',
'url' => url('/')
];
//just change and uncomment url() helper
return [
'name' => 'Larvel',
//'url' => url('/')
];
Well I got stuck at same issue while I was using asset in config file (adminlte.php) of Admin LTE.
Please comment your asset, url while using artisan command in config files like this
[
'type' => 'js',
'asset' => false,
// 'location' => asset('js/waitme/waitMe.min.js'),
],

Hybridauth + composer: how to add custom providers

I'm converting a php project to use composer as dependency manager.
The dependencies are loaded via this line in my main script.
require 'vendor/autoload.php';
One of these dependencies is hybridauth (version 2.9). Since using Composer, it throws 'file not found' errors when looking for custom providers files.
For instance, my main controller calls Hybrid like this:
$config_file_path = dirname(__FILE__) .'/hybridauth/config.php';
$hybridauth = new Hybrid_Auth( $config_file_path );
Now, here is the config file. The provider i'm using is "Facebooktest".
Note that I had to specify the path via the [wrapper][path]; array key to get to the next error message.
return
array(
"base_url" => WWWROOT."/auth",
"providers" => array(
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxxxx"),
"scope" => "email",
"trustForwarded" => false
),
"Facebooktest" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxx"),
"scope" => "email",
"trustForwarded" => false,
"wrapper"=> array(
"class"=>'Hybrid_Providers_Facebooktest',
"path"=> './controllers/hybridauth/Hybrid/Providers/Facebooktest.php'
)
)
),
"debug_mode" => false,
"debug_file" => "",
);
The error message (with trace):
require_once(/path/to/composer-project/vendor/hybridauth/hybridauth/hybridauth/Hybrid/thirdparty/Facebook/autoload.php): failed to open stream: No such file or directory
[vendor/bcosca/fatfree/lib/base.php:2174] Base->error()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] Base->{closure}()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] require_once()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Model.php:99] Hybrid_Providers_Facebooktest->initialize()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Adapter.php:101] Hybrid_Provider_Model->__construct()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:278] Hybrid_Provider_Adapter->factory()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:230] Hybrid_Auth::setup()
[controllers/auth-action.get.php:19] Hybrid_Auth::authenticate()
I find it strange that I now need to modify paths inside the "vendor/hybridauth/" project. It defeats the purpose of using a dependency manager. Surely, I must be doing it wrong.
Can you advise?
Check my answer to another question here
If you have recently installed Hybridauth through composer you probably have downloaded v2.9.2, which contain a bug in their Facebook class that replace the vendor path from yours to hybridauth/vendor, causing such issue.
I suspect you created that Facebooktest class by copying their Facebook class and therefore sustained that error. Either update to their dev branch and copy that Facebook class, or simply use other provider class as template for your custom provider class.

Laravel 5 - change default log location, move log file outside the app

How can I change default log file location <project-name>/storage/logs/laravel.log to something like /var/logs/<project-name>/laravel.log?
I resolved this case by using errorlog logging model and configuring webserver.
1. Configure Laravel:
In config/app.php configuration file:
'log' => 'errorlog'
Read more about Laravel log configuration: http://laravel.com/docs/5.1/errors#configuration
2. Configure webserver (in my case Nginx):
error_log /var/log/nginx/<project_name>-error.log;
For those who don't want to use errorlog and just really want to replace the file to log to, you can do this:
\Log::useFiles(env('APP_LOG_FILE'), config('app.log_level', 'debug'));
$handlers = \Log::getMonolog()->getHandlers();
$handler = array_shift($handlers);
$handler->setBubble(false);
on App\Providers\AppServiceProvider.php or any Provider for that matter. This will log to the value of APP_LOG_FILE instead of the default laravel.log. Set bubbling to true and the application will log on both files.
For anyone still coming across this post in hopes of changing their log file location, I believe this is now easier in newer versions of Laravel. I am currently using 8.x
In your /config/logging.php you can define the path for your single and daily logs. Just update whichever one your are looking to change. Just make sure you also include the name of the log file, not just the path to where you'd like it saved.
'single' => [
'driver' => 'single',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
]

laravel rename lara_admin bundle name in url

I am using lara_admin bundle for my admin panel which is accessible under msmohan.com/lara_admin path.
I don't want to show the lara_admin in the url. So can anyone tell me is there any option for renaming the url link?
When you install a module and register it, you set it up like with this configuration:
'lara_admin' => array(
'handles' => 'lara_admin',
'auto' => true,
),
When the bundle registers routes, it uses that handles key as the basis for the route. So in the bundle's routes.php file, you can see:
Route::get('(:bundle)/login', 'lara_admin::sessions#index');
See that (:bundle)? That tells Laravel to look up the handles key. So if you change your registration for the lara_admin bundle to:
'lara_admin' => array(
'handles' => 'admin',
'auto' => true,
),
It will now be at /admin/login, for example.

Resources