Please help diagnose Laravel path problem

I’m trying to move a Laravel 4.2 site from a remote server to a local server and am coming across some kind of path problem that I hope someone can help diagnose.

I am copying the database and site files from the perfectly functioning remote site and trying to reproduce locally.

The problem:
When loading the site on the local server (at http://localhost) I get 404 not found for the page http://localhost/login. From this, I would infer that the local site starts correctly by reffering to index.php which eventually sends the site to /login but this destination is obviously not setup correctly. If I manually edit the url in the browser to insert ‘index.php’ (http://localhost/index.php/login) the login page loads and I can log in to the site which then continues to function with urls incorprating the ‘index.php’ file in the address bar (I know that index.php is not meant to be part of the url and is not displayed on the remote site). At this point I have other data loading problems with the site but am hoping if I rectify the paths problem it may sort out the rest.

I initially suspected a htaccess file and mod_rewrite. The local apache setup has mod_rewrite enabled and I have copied the .htaccess file from the working remote site but I am not sure if the problem is with this file?

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

The remote site is set up with /var/www/ as the root of the app with /var/www/public as the publically accessible portion. I have setup the same directory structure on the local machine.

My Laravel kowledge is limited so I’m not sure if the htaccess file is the problem or whether there is something else I am missing that might be more obvious to a Laravel developer.

Not sure what the next step to diagnosing this would be and hope that someone can advise?

Thanks

I have had issues in the past with Laravel URLs and localhost (I use XAMPP), so it was recommended to me that I set up a local development environment such as Homestead.

That sounds like a good suggestion but my ultimate aim is to have the site running on an existing local machine running Ubuntu 14.04.3 so using Homestead or other Virtual Machine image wouldn’t be addressing the local environment issues I am currently trying to overcome.

Are Laravel URLs notoriously incompatible with a regular LAMP setup?

Nope. It works fine. Consider setting up an “out of the box” Laravel demo app to see what the default htaccess looks like. Really should not need any changes. I suspect you may need to setup a virtual host? You will probably want to do that anyways for development. And consider checking your apache logs.

Setting up a virtual host was eventually my solution, because I struggled with the VM. I Googled and asked everywhere, and the consensus was that localhost had issues with this sort of thing. Here is my initial struggle with it. You might find this informative - https://www.sitepoint.com/community/t/laravel-5-redirect-problem/195462/2

Thanks for the advice I’ll take a look at the apache logs, I have Document Root pointing to the public folder in /var/www/public in /etc/apache2/sites-available/default not sure if I need anything beyond that in vhosts as I’m not looking to add any kind of domain to this and intend to run from http://localhost.

This might be a silly assumption on my part but would like someone to clarify… Are you able to run Laravel 4.2 sites by just transferring the sites files from one server to another WITHOUT installing composer/Laravel on the destination server?

Reason I ask is that I’ve assumed that Composer/Laravel was only needed for setup and creation of Laravel sites and that processing of the final site files is down to a regular Apache instance?

@Webmachine, just noticed your reply after posting my last. Thanks will take a closer look at the vhosts declaration and see if it makes a difference since that is looking like the general concensus.

Bingo. It was indeed the vhost setup that was at fault. I noticed there was an error in the Directory tag and once corrected the site sprung to life and is looking fully functional. Thanks to WebMachine and ahundiak for pointing me down the right path.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.