0

I just decide to start learning Laravel. By following Getting Started most easy solution for me seems to be to start using laravel installer.

So what I did was installed installer globally and then simply created new project via laravel new laravelapi.

After cli prepare it I edited .env file with my database info and changed APP_URL to http://localhost/laravelapi/ (I'm using XAMPP and laravelapi is name of my project). Unfortunately when I opened browser on that URL I just see the files, not a rendered website.

enter image description here

Funny thing is that when i open http://localhost/laravelapi/server.php site load correctly (it's just some trivial laravel default page)

I was wondering if htaccess works correctly I tried to check if my apache has mod_rewrite as one of his loaded module but it was there. enter image description here

I am really new in it and I obviously missed something important, but I fight here with it for couple hours without any result. Does anyone face this issue before? If so what was the solution?

Andurit
  • 5,612
  • 14
  • 69
  • 121
  • 4
    The document root of a Laravel project is the `public` directory: you need to modify your directory root. The `public/index.php` file is the entry point for your website: users should never be able to access anything outside of `public`. – sam Apr 17 '18 at 17:19
  • index.php is in the public folder move to that directory or you may use the serve Artisan command:`php artisan serve` – iamab.in Apr 17 '18 at 17:20
  • Thanks! It solve my issue. Feel free to add it as an answer to let me mark it as correct. Btw is there a way to easy change that? So root would be on `/` ? – Andurit Apr 17 '18 at 17:24

5 Answers5

3

The Document Root for a Laravel project is the public directory. All user requests should be routed to public/index.php unless the file requested exists within the public directory -- e.g: assets.

You can change the document root for an xampp operated project by following the steps provided in this StackOverflow answer.

sam
  • 5,459
  • 6
  • 32
  • 53
0

Its not good practice to access project through "http://localhost/laravelapi/public"

Probably you will face problems for symbolic links or while hosting your project. It's good to have vHost for your PHP projects.

You can create a vhost for xampp and add document root upto the public directory of your project for Laravel, like as "../Project/laravelapi/public".

Also you can use inbuilt development server command as php artisan serve which will start your server on "http://localhost:8000".

More helpful links 1. Laravel Documentation - here 2. vHost for Xampp - Here

Akshay Patil
  • 27
  • 2
  • 11
0

I got the same issue were two reasons behind the error. one is not a proper .htaccess file placed in the root directory. other php version is not compatible with your laravel current version (low PHP version).

Parveen Chauhan
  • 1,396
  • 12
  • 25
0

You can create another .htaccess file in the main directory which will indicate that your project root is the PUBLIC folder. It will solve your problem. you can try the sample code below.

 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Faisal Mirza
  • 63
  • 1
  • 12
-1

I had same issue but I solved this problem. When we install Laravel then .htaccess file is in the public folder.

  • Cut the .htaccess file from the public folder
  • Paste this file in root folder of project
Sumit Kumar Gupta
  • 2,132
  • 1
  • 22
  • 21