Reputation: 5441
I've recently started learning Laravel but there is one problem which I don't know why it occurs. My current Laravel project is located at wamp/www/codebright
. When I access localhost/codebright/public
I see the welcome page to Laravel.
When I create a simple routing:
Route::get('my/page', function()
{
return "Harro world";
});
and trying to access:
localhost/codebright/public/my/page
it returns with 404 error, not even with Laravel error. I've also tried to access: localhost/codebright/my/page
and still.
However, if I type in CMD php artisan serve
and open a server on 8000 port and then access:
localhost:8000/my/page
it works just fine. I would like to know why my first method without the artisan
command didn't work.
Thanks in advance!
It seems like that if you have XAMPP installed, none of the problems mentioned above and in the answer comment section are occurring. Basically, if you are using XAMPP, you most likely won't get any error and the program will work just fine.
Upvotes: 3
Views: 3795
Reputation: 14232
It is indeed possible to do what you want but if you're not using artisan serve
you must have a webserver set up correctly. From your original post you obviously have a webserver set up as you get the welcome page, but it looks to me like one of the following:
.htaccess
file in placeAllowOverride All
(which is required to allow .htaccess
files to work)mod_rewrite
turned onYou should check these out. As a minimum, Laravel requires a way to turn URIs that don't exist as real files (my/page
) into something it can fake a page for. This pretty much requires the use of mod_rewrite
and an .htaccess
file to specify the rules.
Explanation of the difference between using Apache and artisan serve
: artisan serve
does not use a 'dumb' webserver like Apache and instead uses a webserver built into PHP which has knowledge of how to handle 'non-existing' URIs that you browse to, which is why you don't need mod_rewrite
and the .htaccess
file.
Upvotes: 3
Reputation: 322
Have you created virtual host for your laravel project?
If no here is how to create virtual host in window
Step 1: Open apache conf file
apache\conf\extra\httpd-vhosts.conf
Add below code in last line.
<VirtualHost *:80>
ServerName www.mark-thomas.loc
DocumentRoot E:\wamp\www\codebright\public
SetEnv APPLICATION_ENV "development"
<Directory E:\wamp\www\codebright\public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
E:\wamp\www\codebright\public
is your laravel app path, you can replace it with your folder path.
Step 2: Open-> Windows\System32\drivers\etc\hosts
Add your ip address in list of IP address
192.168.1.231 www.laravel.loc
Restart your apache server hit http://www.laravel.loc/my/page
. Now you will see your message!
Upvotes: 0