editor@linuxhint.com

Laravel Won’t Load In Browser After Install – Not Working

Laravel Won’t Load In Browser After Install – Not Working

Problem

I have Ubuntu running as a vagrant box.

After installing Apache, PHP, MySQL, mcrypt, phpmyadmin, composer I tried to run the app in my browser.

I have issued the following command: composer create-project laravel/laravel learning dev-develop

It is downloaded everything successfully.

But nothing show up when I browse to:

study.dev/learning study.dev/learning/public

Just to be sure, I set all of my permissions to 777.

Here is my Apache enabled site configuration:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/s287/html/laravel/public

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Solution

You can use .htaccess same

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Or you can use another solution follow step by step

  • Step:1: move all files from public directory to [path_root]/laravel/
  • Step 2: Now, you don’t need the public directory so you can remove it
  • Step 3: now open index.php and make the following replacements
require DIR.'/../bootstrap/autoload.php';

to

require DIR.'/bootstrap/autoload.php';

and

$app = require_once DIR.'/../bootstrap/start.php';

to

$app = require_once DIR.'/bootstrap/start.php';
  • Step 4: now open bootstrap/paths.php and change public directory path:
'public' => DIR.'/../public',

to

'public' => DIR.'/..',

And in apache

<VirtualHost>
ServerAdmin webmaster@localhost
DocumentRoot /home/s287/html/laravel/

ServerName study.dev
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>