vivoconunxino vivoconunxino - 9 months ago 42
PHP Question

Laravel css and js gives a page not found, avoid specify index.php

I recently bought a VPS and I'm trying to deploy there a personal laravel project which runs perfectly in localhost.

What I've done is to tar all the project and decompress it on the VPS (/var/www/). I've installed a LAMP, and create the site configuration (/etc/apache2/sites-available/ and enabled it (creating the link on /etc/apache2/sites-available) like so:

<VirtualHost *:80>
DocumentRoot "/var/www/"
<Directory "/var/www/">
AllowOverride all

It's a laravel 5.1.26, with the tipycal .htaccess under the public dir:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

The site works but it's not loading the resources like .js or .css files. Checking the link, for instance:

I got a Laravel error: 404 Uups, page not found.

Any help for making it work please?

Ownership is 1000:apache2, and permissions are the same that in my localhost (except public that now is 777 just to be sure).

Edit: I followed Huzaib's advise and now it loads everithing, the remaining problem is that now I have to address the site as
it's not working.


In your apache configuration, DocumentRoot has to be a directory not a file.

DocumentRoot "/var/www/"

Make the advised change and then restart the apache2 service.