Assets not loaded in laravel - php

I'm new using Laravel. I'm having problems installing a Laravel project when I try to serve it. The project run well, although it's not loading anything in the public folder. This affects all the scripts or css in the web page.
Browser claims error 404 although files already exists.
I figure it out that the problem is that the public folder it's not included and the router responds with a 404 error for any file located there.
Anyone have idea of what's going on here and how can I solve it?

Related

No controllers folder in Laravel project

I have downloaded a project from some website. When i run php artisan server it runs successfully shows server has started on 127.0.0.1:8000. When hit localhost:8000 in browser it gives http 500 error. So i checked the storage/logs/laravel.log file its blank, the logs are not going there. I don't know why. Apart from this there is not http folder inside app folder which contains controllers. So I go through the routes/web.php to see which controllers are being used so i found 'RegisterController', 'LoginController' written in routes file. So i searched for these controllers in whole project I found 'RegisterController.stub' inside 'vendor/hesto/multi-auth/src/stubs/Controllers'. I don't know how to run this project. I have attached the screenshot of app directory.

NotFoundHttpException Only for the CSS and JS files

So for context, the application is a portal for my company that we have hosted on the main production server. Then we have the developer version on a different server. Same exact application but on a different VM and has a different url. That was all set up before I got put in charge of it. Now we want to make an alpha server as the dev server can affect the main database. So for the alpha we need to pretty much have it be exactly like dev, but once it's built, copy the database to a separate db and disconnect it from the main one.
But right now the issue is setting it up. I got Apache2 setup and the site all put together. Now the issue I'm running into is that it's showing the site but not running any of the CSS or JS. The laravel log shows this:
[2019-02-20 11:33:51] local.ERROR: User: test Route:
https://test/app/portal/final.css File:
/var/www/laravel/bootstrap/cache/compiled.php Line: 8335
Class:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Exception: exception
'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in
/var/www/laravel/bootstrap/cache/compiled.php:8335
The same error comes up for the js file but I don't want to post that as it is the exact same error.
And the output of my site right now is just a bunch of links and text in a left tabbed column on the left.
I assume this is due to something not being installed or a config file not reading properly. The code for the site is all just git fetched so it's exactly the same as from the other two servers. The only difference is packages installed into the actual server. It seems that the css and js files aren't loading for some reason. I tried a bunch of other threads and fixes with no luck.
PHP Version is PHP 5.6.40-1+ubuntu18.04.1+deb.sury.org+1 (cli)
Apache2 for the server.
Composer version 1.5.6
Laravel 5
Thank you for any help.
Apache Config: https://drive.google.com/open?id=1im9voo0xqlyuf48gX-JJsRu00f0ym1UX
The CSS and JS files are in the public folder under css and js folders respectively.
Like I said, everything works just fine on the two servers already in place and the filesystem and code is the exact same at this point. The only thing that can be different is apache, laravel, and php.
Are you using Laravel mix with version ? If so, you need to import the css like :
<link rel="stylesheet" src="{{mix('final.css')}}">
or use the asset function just to be safe for any CSS/JS you need to import.
Three possibilities...
Apache root folder
First, the document root in your apache config (or site-enabled) needs to be the /public folder. In which case your request wouldn't hit the .htaccess and redirect to index.php and you'd get a bad route error. So this is a less likely option.
Compile Your .css and .js
You haven't compiled the .css and .js using Webpack (or gulp or whatever if you don't webpack) on the new server. In this case, the .htacess would send the request to index.php and Laravel would look for a route (which is what your error looks like) and then you'd get an error about an invalid route. Note the .css and .js should be in the .gitignore if you use git to clone the project, making this an easy thing to overlook and to have happen. Nice thing is that if node and npm are setup and you use webpack, it should just be a:
npm run development
The sad thing is getting node and npm and webpack all working isn't always as simple as it should because of versions and such.
Missing or not reading the .htaccess
Finally, your .htaccess isn't being read or didn't get copied over, which would mean that that / route would magically work, but any other routes wouldn't... Though, in that case your .css and .js should still work -- but not likely.

Custom Module using Bonfire CI on Cpanel

I have developed my own module using bonfire on CI. The application works best locally. When I deploy it on Cpanel, the main pages until login screen work well.
As soon as I try to hit the pages of my module, it gives me a 404 error. They are of the pattern: http://website.com/admin/content/blog/edit etc.
I have edited .htaccess in the root directory, but I am not sure what to put in .htaccess in Bonfire_root/public. I suspect the problem lies here but I am unable to troubleshoot successfully.
As #nishant-nair mentioned, the solution was to Capitalize the first character of the controller file names.

Laravel 5.2 - Staging to Live Server : 500 Internal Server Error

I have a Laravel 5.2 project working fine locally, after uploading to a live server I have a 'laravel' folder in my root directory and public folder under 'public_html/testsite'
My 'index.php' points to the correct '/bootstrap/autoload.php' and '/bootstrap/app.php'
Upon going to my 'url/testsite/' I get a blank page only (was working fine L5.0) firebug shows : 500 Internal Server Error with HTML : Reload the page to get source for...
index.php is loading by testing with die() before any 'require' methods, but after 'require... autoload.php' the die() is not working, however it is successfully calling autoload.php as a die() works within this file.
I'm not sure if this is a .htaccess issue, or maybe I had to set something up in cPanel last time for this folder (I can't remember). I'd appreciate any help!
Please note this Laravel project sits as a test site in a /testsite/ folder along with my current live site files.
Amongst changing many things at once, I appeared to have solved this by setting up a subdomain within cPanel and setting this to my testsite/ folder.
This was on a server with my current website live under public_html/ and setting up a test laravel app(website) with under public_html/testsite/ to work as an independent site for testing.
The typical "change permissions on storage folder" suggested elsewhere on stackoverflow did not solve my issue so hopefully this helps someone in the same boat.

Error: Template Directory Not Found

I have cloned a git repo that someone made for a CodeIgniter website. I have a WAMP server set up fine in my computer and it works fine. In the Apache modules I enable the rewrite_module and in the PHP Settings I enable short open tag. I also put my database settings in the application\config\database.php file. After that, I put the CodeIgniter folder in the C:\wamp\www\CodeIgniter folder.
Now the problem is that when I go to localhost/CodeIgniter I get this:
Error: Template Directory Not Found!
I have looked for several hours online for this error but I could not find anything similar. If someone has seen this error before and knows how to solved it I will really appreciate any help or if you could point me in the right direction since I am new to CodeIgniter.
It sounds to me like your app is using a third-party Template library, and a config is incorrect
Search your application dir for "Template Directory Not Found" - that will take you to where the error message is in the code, and you can then figure out what library is calling it. Or, take a look in your application/config - most likely there's a file for it
"Template Directory Not Found" is not part of Codeigniter.

Categories