missing images and home page when moving laravel 5.2 project to live server - laravel

images works fine in localhost as src="/lr/public/bootstrap/images/photo.jpg"
but don't work on live server
error messages on live server is failed 404 not found www.mysite.com/lr/public/bootstrap/images/photo.com
note : when i remove /lr/public images works on live server
my cpanel root directory is /home/ad
in /home/ad >>
i have folder'lr' that containe my project and i deleted folder public in it
in public_html >>
i have contents of folder public >> bootstrap - uploads - index.php ..... etc

Looks like you didn't link your images correctly.
I believe the link should be:
www.mysite.com/bootstrap/images/photo.jpg
not:
www.mysite.com/lr/public/bootstrap/images/photo.com
Use: asset('bootstrap/images/photo.jpg') for linking files from your public folder.
Blade example. <img src="{{ asset('bootstrap/images/photo.jpg') }}">
Make sure 'photo.jpg' exists in 'public/bootstrap/images/' directory

Related

Laravel App Not Loading CSS From Public Installation Not In public_html

I've installed a pre-made Laravel app and followed the documentation to extract it to the public root except in the documentation they are installing it into public_html, but I have it in a subdomain in a folder named "test" which is on the same level as public_html.
All the CSS and JS should be loading from the public subdirectory, but they try to look for it in the main root folder.
For example, this file returns a 404 error:
https://test.mydomain.com/css/style.css
The file is actually at this location:
https://test.mydomain.com/public/css/style.css
The absolute path of the file is:
/home/mydomain/test/public/css/style.css
Instead of:
/home/mydomain/public_html/public/css/style.css
What environment or config file isn't set correctly and how do I set it to use the correct directory?
UPDATE
Changing the ASSET_URL to "public" fixed the first issue, but now the same thing is happening with the admin.
The app tries to load the dashboard with this URL:
https://test.mydomain.com/admin/dashboard
The page loads all the assets normally when I remove the word "admin" from the URL:
https://test.mydomain.com/dashboard
But this doesn't work for all the pages.
You can try to put public directory path in below given conflagration file.
Config File Path : config/app.php (asset_url)
'asset_url' => env('ASSET_URL', 'https://test.mydomain.com/public/')

Uploading images to Public_html file rather than public project file

Had this working but just updated my website on the server and it seems to have made all my uploaded files head to my public folder in my project rather than the public_html. Any idea on which file i must have uploaded and the fix?
You said you had it working before.
Was that on the same server...live?
If so, then could that be a server issue and not necessarily laravel issue?
Maybe you should ask your host for help and clarifications about what changed?
If you are convinced it was about what you changed...then care to show us?
Ideally if the server is cpanel, you will want to upload all your laravel files into your home's directly...then all your /public folder content into public_html
It will look like this:
.cpanel/
app/
etc/
bootstrap/
mail/
public_html/
content from your laravel /public directory
vendor/
...etc
You also need to go into your /public_html and edit the index.php content:
require __DIR__.’/../vendor/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And make sure it points to the correct location of your bootstrap folder..if you follow the structure above, then its ok.
Lastly, confirm that your PHP is indeed >= PHP7.0
With help from this answer: https://stackoverflow.com/a/50261573/3475551
I managed to get laravel to save uploaded files to my servers public directory instead of app/public.
Edit app/Providers/AppServiceProvider.php like this:
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../../public_html');
});
}
Hope this helps.

Laravel - link to a file saved in storage folder

When we do something like this:
Storage::disk('local')->put('file.txt', 'Contents');
How do you make a link to that file in a view? Something like this:
Download File
there are so many things in documentation and yet not even one example how to create a link to that file
Try this command on your terminal : php artisan storage:link, then laravel storage become public access.
Download File
UPDATE:
According to laravel docs, You can get the URL to the file like this:
use Illuminate\Support\Facades\Storage;
$url = Storage::url('file1.jpg');
Remember, if you are using the local driver, all files that should be
publicly accessible should be placed in the storage/app/public
directory. Furthermore, you should create a symbolic link at
public/storage which points to the storage/app/public directory.
Hope this helps!
Scenario--(working from a fresh Laravel 5.6 project install for reference):
With the existing default paths being /public and /storage/app/public and you want to physically store your logo.png image in the /storage folder and render it on your Welcome page, the process would go something like this:
In your terminal, navigate to your Laravel project folder.
Run command php artisan storage:link
Now create the folder /images in your /storage/app/public folder which gives you /storage/app/public/images.
Look in your /public folder and you will see the (shortcut) subfolders /storage/images
Copy a test image named logo.png into the /storage/app/public/images folder.
In your project's welcome.blade.php under /resources/views paste the
following code over the existing code:
<div class="content">
<div class="title m-b-md">
Laravel
<div>
<a href="/">
<img src="{{url('/storage/images/logo.png')}}" alt="Logo Image"/>
</a>
</div>
</div>
</div>
Save and open your project in your browser and you should see the logo image.
Having said all of that, later on you need a pdf folder to store uploaded pdf
files. Easy, just create a new folder in /storage/app/public called /pdf and
automatically the shortcut will appear in the /public folder. It is a once and "for all" solution.

Image not displaying in view. Laravel

In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.
My image is located in my project's public/images/users/3/profilePictures/
Here is my <img> in the view.blade.php
<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }} {{ $follower->last_name }} Profile" width="50" height="50">
However I get this when I load the page:
When I inspect the image with firebug I see this:
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
Anyone know why this is happening?
This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Or as #lukasgeiter mentioned you can simply use asset('path/to/asset') helper.
You can try with the
php artisan storage:link
else you can use this
A simple fix for the issue (linked broken error)
in .env file
APP_URL=http://localhost
this replace with the
APP_URL=http://localhost:8000
then the issue will be fixed.
delete already generated symlink and then run this command
php artisan storage:link
if you are using laravel, consider excluding public folder or any folder where your public files are store in .htacccess from folders that laravel control.
Do it like this in .htaccess
# Exclude directory from rewriting RewriteRule ^(public/) - [L]
Storage location before (Not Working) :
<img src="{{asset('storage/app/public/media/productImages/'.$list->image)}}" alt="" srcset="">
Working storage location :
<img src="{{asset('storage/media/productImages/'.$list->image)}}" alt="" srcset="">
Else try :
Deleting all the linked/shortcut folders created in public folder
Then recreating the link by running :
php artisan storage:link

Uploading Laravel Project onto Web Server

I am trying to upload my Laravel project onto my web server, but my past two attempts have been unsuccessful. I believe I am not uploading the files to the right location.
This is my web server's structure ->
Am I correct to say that I need to upload ALL of my laravel files into public_html?
This is my Laravel project's directory :
EDIT : I have now added all the files onto the root folder, and public into public_html, however none of my routes seem to work. (They work perfectly on localhost). Everything throws a 404
No, but you have a couple of options:
The easiest is to upload all the files you have into that directory you're in (i.e. the cPanel user home directory), and put the contents of public into public_html. That way your directory structure will be something like this (slightly messy but it works):
/
.composer/
.cpanel/
...
app/ <- your laravel app directory
etc/
bootstrap/ <- your laravel bootstrap directory
mail/
public_html/ <- your laravel public directory
vendor/
artisan <- your project's root files
You may also need to edit bootstrap/paths.php to point at the correct public directory.
The other solution, if you don't like having all these files in that 'root' directory would be to put them in their own directory (maybe 'laravel') that's still in the root directory and then edit the paths to work correctly. You'll still need to put the contents of public in public_html, though, and this time edit your public_html/index.php to correctly bootstrap the application. Your folder structure will be a lot tidier this way (though there could be some headaches with paths due to messing with the framework's designed structure more):
/
.composer/
.cpanel/
...
etc/
laravel/ <- a directory containing all your project files except public
app/
bootstrap/
vendor/
artisan
mail/
public_html/ <- your laravel public directory
I believe - your Laravel files/folders should not be placed in root directory.
e.g. If your domain is pointed to public_html directory then all content should placed in that directory. How ? let me tell you
Copy all files and folders ( including public folder ) in public_html
Copy all content of public folder and paste it in document root ( i.e. public_html )
Remove the public folder
Open your bootstrap/paths.php and then changed 'public' => __DIR__.'/../public', into 'public' => __DIR__.'/..',
and finally in index.php,
Change
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
into
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
Your Laravel application should work now.
If you are trying to host your Laravel app on a shared hosting, this may help you.
Hosting Laravel on shared hosting #1
Hosting Laravel on shared hosting #2
If you want PHP 5.4 add this line to your .htaccess file or call your hosting provider.
AddType application/x-httpd-php54 .php
In Laravel 5.x there is no paths.php
so you should edit public/index.php and change this lines in order to to pint to your bootstrap directory:
require __DIR__.’/../bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
for more information you can read this article.
Had this problem too and found out that the easiest way is to point your domain to the public folder and leave everything else the way they are.
PLEASE ENSURE TO USE THE RIGHT VERSION OF PHP. Save yourself some stress :)
All of your Laravel files should be in one location.
Laravel is exposing its public folder to server. That folder represents some kind of front-controller to whole application. Depending on you server configuration, you have to point your server path to that folder. As I can see there is www site on your picture. www is default root directory on Unix/Linux machines.
It is best to take a look inside you server configuration and search for root directory location. As you can see, Laravel has already file called .htaccess, with some ready Apache configuration.

Resources