简体   繁体   中英

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/anuncios.com.conf) and enabled it (creating the link on /etc/apache2/sites-available) like so:

<VirtualHost *:80>
ServerName 137.94.162.235
DocumentRoot "/var/www/anuncios.com/public/index.php"
<Directory "/var/www/anuncios.com/public">
AllowOverride all
</Directory>
</VirtualHost>

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
    </IfModule>

    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]
</IfModule>

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

http://137.94.162.235/css/externos/bootstrap.min.css

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 137.94.162.235/index.php otherwise 137.94.162.235 it's not working.

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

DocumentRoot "/var/www/anuncios.com/public/"

Make the advised change and then restart the apache2 service .

Solved,

Firstly, I followed Huzaib Shafi answer and changed the /etc/apache2/sites-available/anuncios.com.conf changing the DocumentRoot to the public folder (not the index.php).

Finally, to avoid having to specify the index.php I had to enable the apache mod rewrite from the command line:

a2enmod rewrite

That allows apache to follow some instructions from the public/.htaccess .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM