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?

3
  • 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. Commented Apr 17, 2018 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 Commented Apr 17, 2018 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 / ? Commented Apr 17, 2018 at 17:24

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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>

Comments

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

Comments

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).

Comments

-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

1 Comment

Why is this downvoted and it works? Make sure you restart apache once you have moved the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.