Assets wont load after renaming public folder in Laravel - php

I'm using laravel version 5.3
I renamed my public folder to public_html by add following lines to my
AppServiceProvider
I update/renamed following code in register method.
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../public_html');
});
}
After that any of my assets wont load i faced 404 error for all of them. what should i do now?

I strongly suggest you do not use a hosting webspace for Laravel.
VPS is cheap as heck these days, get a VPS and use Laravel Forge if you don't want to manually install the environments.
Use git to deploy your code on to the server.
Even if you solved this very problem with symlink(I don't think you have the permission), you will still encounter other problems because you won't have the permission to install composer dependencies.
By the way, what Dennis suggested would not matter I believe, it still points to the same destination.
remove the first / of /../public_html

Related

Laravel add old path when I try to use a resource

I created some resources with php artisan, located in Http/Resources/Api/V1
Then I moved all at the root folder : Http/Resources, and deleted the Api/V1 folders
But now, my application uses an old version of my resources, I dont know why.
For example, in my controller I have :
public function show($id)
{
return new UserResource(User::findOrFail($id));
}
But the resource used is an old one, it doesn't even exists anymore
When you moved your resources from Http/Resources/Api/V1 to Http/Resources make sure you change the namespace in the resource files to reflect those changes.
After changing the namespaces make sure you use the correct includes at the top of your controllers because they will be different after you changed your namespaces.
If you did all the above steps make sure to run:
composer dump-autoload
This will fix any autoloading issues after you changed namespaces.

How to put laravel 5.3 project on shared hosting

I made a laravel project on my localserver. I just copy the project folder and pasted on my web server in public_html folder. It's giving an error when i open it.
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Can anyone please let me know step by step how to put my laravel project on web serve?
Well there are three ways to upload and make workable on shared hosting which I came to know.
Rename server.php file to index.php (which is not the correct way)
Shift public/* to root (also, its not the correct way)
Need to add a line in public/index.php after initialization of $app
$app->bind('path.public', function() {
return _DIR_;
});
and that's proper way as per my knowledge.
(My last answer was deleted before I could submit my edits, so here's another, more complete answer)
There is an easy answer, and a long answer.
Long answer
The most important part to know is that the only part of Laravel that should be accessible to the public is in the public folder. Which means that, on your shared host, the content of public should reside in whatever folder is the public on your host (they usually are named "www", or "public_html", but it can be anything, really).
I'm going to assume here that you have only one project on your account and say that, if it's the case, you now only need to upload every other file and folder at the same level as the public folder you have and set the correct permission to the storage folder.
In the end, if the only thing you do is upload all of your project to the root folder of your account, then rename Laravel's public folder to public_html, this is supposed to work (of course, assuming that you can also use the CLI and call artisan and composer commands).
Easy answer
If you can use the command line and create synlinks on your host, you can simplify your life by uploading all of your project into a folder outside of the public_html folder and symlink public to your public_html like so: ln -s /full/path1/project/public /full/path/to/public_html
Detailed answer and more tips
You can read this article that goes into more detail and gives commands to achieve everything. I tried to keep my answer as concise as possible, so if you want a more step by step approach, this link or a bit of google searching will do the trick!

Laravel 5 view not found

I'm having the weirdest error in Laravel 5, and I haven't had this happen in any of my other projects.
Problem
I receive the following error when I try to hit my app
No such file or directory (View: /home/vagrant/Code/resources/views/layout/master.blade.php) (View: /home/vagrant/Code/resources/views/layout/master.blade.php)
However, in my directory structure
And in my blade template
#extends('layout.master')
#section('content')
jfoewifjewo[ij
#endsection
In my controller
public function index()
{
return view('home');
}
Anyone else hit this issue? I've never encountered it before. Yes storage has read/write on both local and homestead.
UPDATE: I'm on Laravel 5.0.13
This issue lies with using Laravel Elixir with homestead. I went back to MAMP to see if I got the same error and what it told me was that I was missing the rev-manifest.json file in public/build. After some digging, I found out that if you don't apply the "versions" function to the elixir function in your gulpfile, the build folder won't be generated and calls to the "elixir" function in your blade templates will fail. This appears to bubble up as an error in finding the view, when it's actually an issue finding a view dependency.
Use gulp to build your sass or less files for sure, but for the time being stick with just URL::asset() to get your javascript and css file paths generated until all the kinks with elixir are worked out.
This is a well know version issue Laravel 5.0.1 (#Zarathuztra version) Here is some comments about the issue: https://laracasts.com/discuss/channels/general-discussion/laravel-5-error-out-of-the-box-with-update-route-throws-an-error
Search for "PratyushPundir" and from them you will see some people having the same issue
Updating Laravel should fix it.
I fix it by add the version. Because after add the version in gulp, it will generate rev-mainfest.json.
original gulp in homestead
elixir(function(mix) {
mix.sass('app.scss');
});
I change to
elixir(function(mix) {
mix.sass('app.scss')
.version(["public/css/app.css"]);
});
And it works.

Laravel, dump-autoload without Shell Access

I have two controllers with the same name:
app\controllers\CareersController.php (for public use)
app\controllers\Admin\CareersController.php (for admins)
Because of the naming conflict, I added namespace admin; to the admin controller.
Everything works fine locally but when I uploaded the new admin controller to my server, I get an error: Class Admin\CareersController does not exist
From what I understand, the fix is:
php artisan dump-autoload
and composer dump-autoload
However, I don't have Shell access to run those commands and composer isn't installed on the server anyway. So, is there a way to reload the auto-load file without Shell access?
Run composer dump-autoload locally. Then, in your hosting site,
you can update two files, autoload_classmap.php and autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server.
You dont need shell access. Artisan includes a dump-autoload function. You can just it via a PHP call within your app:
Route::get('/updateapp', function()
{
\Artisan::call('dump-autoload');
echo 'dump-autoload complete';
});
Edit: just noticed you wrote "composer isn't installed on the server anyway". Not sure what will happen - try the command above and let us know.
If it doesnt work - then just run composer dump-autoload locally - then upload your new autoload.php.
As a side point - is there any option to switch servers? You going to keep running into various issues if you dont have command line & composer access. You could just use Forge and spin up a new server on DigitalOcean, Linode etc in less time than it would take to fix this issue :)
I was using a shared hosting by client's requirements and did not have access to ssh or composer, what I did was to composer dump-autoload on my local machine and then I figured that for my project autoloader just updates composer directory in my vendor directory, so I just re-uploaded that one folder after each dump-autoload and not all vendor directory
Edit:
Another pitfall for me that generated the same error but the cause was something else, I develop on Windows machine in which file and directory names are case insensitive when deploying to Linux server, the framework could actually not find my controllers so I changed
Route::get('/news', 'newsController#index');
to
Route::get('/news', 'NewsController#index');
now it is working, autoload is doing it's job correctly

Laravel 4 - class not found on live server

I'm uploading my laravel 4 app to a testing server which is shared hosting.
I'm uploading to a password protected directory which has a .htaccess file within it. My subdomain points to the public folder.
For the most part they app is working as expected I can log in, view most of the pages however every class that I have created such as a helper class and additional controllers are not being found on the live server yet all works on my local environment.
I've redone a composer dump-autoload and uploaded the composer.json file
I'm not sure where to start with this.
In my upload I've included all the files and folders to the live server (twice now). I read somewhere else I should namespace my classes but why would this help if the main laravel controllers do not namespace?
Confused - all help appreciated
When you do a composer update, if Composer finds anything new it will update some files in the folder
vendor/composer
Like the file autoload_classmap.php.
So, you have to reupload at least this folder too.
Maybe it's about git, you are pushing changings with some certain case sensitive Folders and Files, but git is changing this therefore it will work on Mac and Windows OSs but not on the server.
just use this command:
git config core.ignorecase false
above command for the current repository and you may add --global just after config keyword.
please note that ignorecase option available since version 1.5.6 and I assume you are running 2.0.x but just mentioning!

Categories