Cannot resolve public path when trying to read barryvh/dompdf in laravel - php

I deployed a laravel app to shared hosting. Then I separated the folders into two DOMAIN containing the all the other folders and public_html containing the files in the public directory. I then modified index.php file in public like this
require __DIR__.'/../domain/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../domain/bootstrap/app.php';
The app seems to work well, except for some features like the barrydompdf that gives me the error
Cannot resolve public path
Please any idea on how I can fix this. Thank you all in advance.

This is the most stupid error by DOMPDF.
To resolve this error, all you need to do is to create a public folder in project directory, Although it is of no use.

This issue is submitted to DOMPDF Git already and people have found workaround of it.
Go to this path
vendor/barryvdh/laravel-dompdf/src
Edit
ServiceProvider.php
Search for
base_path('public')
and replace it with
public_path()
OR YOU CAN JUST CREATE A PUBLIC FOLDER IN YOUR CODEBASE DIRECTORY
EDIT:
This happens when your code base has no public folder and you have separated your public folder to public_html.

Never edit the content under the vendor folder
Just add this property in your config/app.php
'public_path' => public_path(),

remplace
'public_path' => null
for
'public_path' => base_path()
to file path
/config/dompdf.php
you can see the same topic here
https://laracasts.com/discuss/channels/general-discussion/cannot-resolve-public-path-dompdf

Related

What is correct method to access Laravel logs from application start.php

Sorry if this seems a dumb question but I am learning how the Laravel framework operates.
I have a working web app that uses the Laravel framework. The log file is set in backend/app/start/global.php
|--------------------------------------------------------------------------
| Application Error Logger
|--------------------------------------------------------------------------
|
| Here we will configure the error logger setup for the application which
| is built on top of the wonderful Monolog library. By default we will
| build a rotating log file setup which creates a new file each day.
|
*/
$logFile = 'log-'.php_sapi_name().'.txt';
Log::useDailyFiles(storage_path().'/logs/'.$logFile);
Log::info('Log file set to '.$logFile);
The last line Log::info() I added to the file and it works ok.
However i need to add similar info logging messages to backend/bootstrap/start.php. I now want to add a Log::info() statement.
I have reference to the Laravel application via the line in start.php
$app = new Illuminate\Foundation\Application;
So my question is; if I am using the Laravel framework what is the correct way to get a reference to the Laravel "Log" defined in global.php. So that I can add a line such as:
Log::info('Using Environment '.$key);
This is what you need to get a reference to Log class.
use Illuminate\Support\Facades\Log;
Using $app['log']->info('Stuff you want to log') should work but I don't think that's a good idea.
This file exists only to create the "app" but you shouldn't need to do anything inside since the config files aren't even loaded that's why you can't use Facades here, no config file => no Facades.

laravel 5.6 host to cpanel on shared hosting

How can a host a Laravel 5.6 app to cpanel on a shared hosting.
Can someone give me an idea
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
\#########my index.php file
You have two methods available, one requiring ssh access. Under no circumstances do you put your entire Laravel directory into the public_html directory.
SSH Access
If you have SSH access you'll want to do the following;
Log into your account and go to your home directory cd ~
Delete the public_html directory
Now you want to upload your Laravel app to ~/laravel
Now you need to recreate public_html as a symlink cd ~ && ln -s laravel/public public_html
No SSH Access
If you don't have SSH access you'll want to do the following;
Upload your laravel installation to somewhere like ~/laravel (above the public_html)
Copy the contents of the ~/laravel/public directory to public_html
Change the path to match your new destination
Your new ~/public_html/index.php should look like the following;
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
after googling around i found that you have to take content of public folder which has index.php file and put it in public_html. now we have to change the content of index.php file i.e just provide the right link of app.php and autoload.php which would be require __DIR__.'/<project_folder_name>/vendor/autoload.php' and $app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php'; also update your .env file and check it should work if it doesnt you have to clear cache and routes using php artisan cache:clear and php artisan route:clear you can do this using ssh or define the function in web.php and then hitting the link
An easy way if your shared hosting team is very supportive for you,
Upload your files to public_html folder, and then incase if you donot have ssh access to server, contact your hosting team and ask them to point your domain name to public_html/public folder as root folder.
And then ask them to execute following command via ssh
composer install
If you want to boost the peformance, please provide them the four commands listed in the following article.
https://www.techalyst.com/links/read/112/boosting-laravel-performance-in-production-server
Laravel 5.6 requires PHP 7.
First check your shared hosting support PHP 7 in Cpanel (PHP Selector), if yes but you have other projects which PHP 5 and you don't want to change default php version, then use this in .htaccess file
For example: public_html/abc/.htaccess
RewriteEngine on
AddHandler application/x-httpd-php71 .php
Then PHP 7 Work and you can work with Laravel 5.6 on shared hosting
laravel -> all laravel file
public_html -> move all folder & file on *public* file laravel to *public_html*
change your index.php on public html
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
don't forget to change your php version to 7.2
The simplest way to host on shared hosting
Create a subdomain on hosting and map it to a folder e.g: "abc"
In folder "abc" upload laravel project zip (with vendor folder) then extract it
Map subdomain to the public folder of laravel i.e. "abc/public".
Create a database & user and assign that user to the database with all privileges
Import the DB dump in the database created above.
Add DB user/password in laravel .env file.
Note: If you face any due to cache remove file config.php in directory bootstrap/cache.
Umm. Shared hosting does NOT support php 7, which larave 5.6 depends on. Have you guys found a workaround. I have been stuck for months with laravel 4.x on bluehost.

How to rewrite or remove public from laravel 5 urls in proper way?

I'm trying to remove the public/index from laravel url, since this is one of the common question so there are lot of tutorials and answer. I also searched about this and followed the #rimon.ekjon answer which is working fine for me it's pretty simple.
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. -- Thats it !! :)
I'm confuse why i should rename or move something from one place to another because there will be a reason why files exist in public folder. I want to show another good answer which is also following the almost same pattern.
I'm thinking that by following above answers' step may be create some issues in future if there will be a new requirement or new feature request in the project.
So can anyone guide me is there any best to rewrite or remove the public/index from laravel 5. I would like to appreciate if someone guide me.
You should configure your web server's document / web root to be the public directory. That way you don't have to copy/move/delete anything.
For apache you can look here.
For nginx you can read here.
I've visited your link and saw really terrible advices.
You do no need to move any Laravel files or modify them. What you need is to setup web server. You need to point it to a public directory which is inside Laravel project root folder.
Please look here for an example config directives for Apache and nginx.
One other option is to symlink the public folder to your server's root folder (e.g. /var/www/). This article is a great guide on how to do this.
On your dev environment however you can use php artisan serve.
In case, if you don't have access to you server config, this is a perfect solution https://stackoverflow.com/a/32580688/5015089 .
Remove public from url without htaccess. It will work on laravel latest versions also.
step 1. Copy all files from public and paste on root directory
step 2. Open index.php file remove ../ from path as given below
Laravel5:
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/bootstrap/autoload.php';
and
require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/bootstrap/app.php';
Laravel 7:
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

Change .htaccess file in laravel 4

I have a problem when upload laravel project on my shared hosting. On that hosting I have two addon domains with separate folders in document root. But when I put laravel project in document root and move everything from public folder in root to remove that "/public" from url, I cant access to my addon domains. I'm getting 500 Internal service error. When I remove .htaccess file I can access to my other domains, but I can't access to my Laravel project. How can I change default laravel .htaccess file?
Well, you should not move everything from public folder, this is a very important part of your Laravel application, it was built this way to separate your application source code from the public files anyone can access, if you make your application root also your public folder, anyone will be able to access any php files from your application, and this is so unsafe...
What you need to do is to point your document root to /serverRoot/applicationRoot/public.
If you really cannot do that, I'm afraid you'll have to edit index.php and try to change thos two lines:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
to
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
And see if it works for you.
EDIT
Laravel's default .htaccess file is there just for rewriting your URLs, so you dont see aindex.php` on them. Basically it does 2 things:
1) If you access your site using http://www.site.com/, internally it will point to http://www.site.com/index.php.
2) When you access your site using http://www.site.com/index.php it hides the index.php part.
This is kind of recursive, because the first step leads to the second one.
Now you have to think and see how this is conflicting with your other domains, because the files you are serving in those domains matters and since we are not aware of what they are, helping more is kind of difficult.

Install a Laravel 4 Application in the Public directory of a site?

Is there anyway possible to install a Laravel PHP application into the same directory?
What I mean is as I see it, you have to install the whole Laravel application 1 directory under the the main Public directory.
I know that you can change the Public directory to anything in the settings but the server my client has, they really need for everything to live in 1 directory.
Current Folder Structure....
app/
bootstrap/
vendor/
public/
artison
server.php
If this was all dropped into a Public directory on the server, then you would have to access the application/website at the domain www.domain.com/public/
I am hoping there is a way to put all these files/folders into a public or www htdocs type folder and still access the application at the root.
I know the main reason to keep the PHP files out of the Public accessible folder is for security but in my clients situation this is not possible the way there server is configured.
Surely there is a way to do this?
Try putting contents of public in same directory as other folders, and then edit your index.php previously in public to look something like this
require __DIR__./bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
I haven't tried this. Just came to my mind right now
Anyway, I'm doing this by keeping app, boootstrap, vendor in / of my hosting, and contents of public are in my public_html. It works fine, and I guess it could be a security plus.

Categories