I have a Laravel app running on XAMPP. I did point the VirtualHost directory at C:/xampp/htdocs/donor/public, which public in this case is Laravel's public folder.
However after I've tried changing the VirtualHost directory to C:/xampp/htdocs, and added the following alias, Laravel's seems not to see the full path of the app (which is http://domain.tld/donor), and recognise only the http://domain.tld/, making it point to invalid URL.
This make all the resources loaded from the wrong URL. Notice that there should be /donor/ in the red circle provided. (Such as, http://url.domain/donor/css/file.css becomes http://url.domain/donor/file.css)
The alias added is:
Alias "/donor" "C:/xampp/htdocs/donor/public"
How can I config this in Laravel so it does its job perfectly?
Related
On a fresh Laravel 8 installation I follow these steps:
php artisan storage:link
Inside /public/storage/ I create folder images/ and inside I paste an image called picture.png
In web.php I define a route like this:
Route::get('/picture', function(
return response()->file(Storage::url("images/picture.png"));
))
However, if I visit this route in browser, the picture is not shown and the following error is thrown:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "/storage/images/picture.png" does not exist
It works only if the url inside response()->file() is prefixed with ./ indicating the current directory like this:
return response()->file('./'.Storage::url("images/picture.png"));
I don't think it is a good idea to work with relative paths locally, the Storage and file methods should handle this. Maybe it is even an issue with the framework.
Any ideas how to go around this hack?
I think you didn't configure the local driver check the documentation https://laravel.com/docs/8.x/filesystem#the-public-disk and look for local driver.
If you configure it right it should return the "/" that you're adding manually.
One of my routes is returning this error message:
Not Found
The requested resource /jackpots was not found on this server.
When I change the route name to anything else e.g. route-1, it works.
Server is running on http://127.0.0.1:8000/jackpots via artisan serve
How can I resolve this?
Edit 1:
Does not work:
Route::get('jackpots', 'JackpotsController#getIndex');
Works:
Route::get('jackpot', 'JackpotsController#getIndex');
Turns out the problem had nothing to do with anything in the routes/web.php script.
In my public directory, I also had a folder with the same name as a URL endpoint i.e.
Folder structure
public
|__jackpots
web/routes.php
Route::get('jackpots', 'JackpotsController#getIndex');
This somehow confuses the php server (as well as apache) into thinking you're trying to access the public/jackpots folder whose permissions won't allow you to do that.
I renamed the public/jackpots folder and the problem was resolved.
I just installed laravel following the instruction on Larvel docs. I chose to use install via composer create project command.
In the routes. php i created a dummy route
Route::get('/', function(){
return 'Front Page';
});
When i access http://localhost/mysite/ It shows directory listing of mysite folder. However when i use http://localhost/mysite/server.php It runs my route closure.
I also tried alternate .htaccess code provided at Laravel's docs but that doesn't work either.
I want to remove the server.php from url.
Thanks in advance for help.
This behavior is expected and this is how Laravel works. The public folder is meant for assets and is also (supposed to be) the webservers root directory.
If you are working on localhost that is not the case and the root directory contains multiple projects.
In order to get rid of public you would have to change virtual host settings.
As mentioned here in the site.
The problem with doing virtual hosts is that other projects in localhost will become inaccessible.
I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)
I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by typing http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache.
In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view:
That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem.
if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!