Hi,
Laravel newbie of one day's experience and extremely keen to see what all the fuss is about. Trouble is I've hit a wall already. Here's my sad story:
I downloaded composer and then ran :
composer create-project laravel/laravel MyDomain --prefer-dist
It all kicked off and installed everything, but routing doesn't work. I can enter the full path to hello.php and it works but if I go to localhost/mydomain with or without trailing space, I just get a file/directory listing. My knowledge of routing from MS MVC tells me that should go through to hello.php, looking at routes.php. I googled this for about three hours last night and went to bed wretched and beaten
It looks like an Apache config issue, many Stack O answers gave examples of VirtualHost entries, .htaccess entries, all of which I tried, none of which worked. I'm surprised it is this hard to get a hello world thing up and running. I'm guessing there is a combination of mod_rewrite, httpd.conf and htaccess to set up but this is the very opposite of intuitive!
So... Currently I have an htaccess file at the domain root with this (plundered from SO)
<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ /index.php [L] </IfModule>
I have a VirtualHost entry thus
<VirtualHost 127.0.0.1:80> DocumentRoot "c:/apache/htdocs/mydomain" <Directory "c:/apache/htdocs/mydomain"> AllowOverride All </Directory> </VirtualHost>
(I thought VH entries were for multiple sites on the same server...I have just the one)
Hmmm.. I just uncommented this line in the httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
and now I don't get even the directory listing - just 404 index.php not found. Aha! I guess that's because my RewriteRule says index.php?? So... what should it be???
Running out of ideas and looking back fondly to my dallyings with yii a year or so back - an ORM enabled web app on suse 12 in about 30 minutes flat.. beautiful.
What am I doing wrong?
Thanks
Mark
Edit - just tried with the suggested htaccess entry from the laravel installation page:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Still just getting a directory listing.
Hey,
If you browse to http://localhost/mydomain/public does that work?
Laravel routes all requests through /public/index.php so you'll need to set your document root to c:/apache/htdocs/mydomain/public
Sam
Hey, thanks for replying. No indeed. That gives me "The requested URL /index.php was not found on this server."
VirtualHost entry is now:
<VirtualHost 127.0.0.1:80>
PHPINIDir c:/php
DocumentRoot "c:/apache/htdocs/sortedsounds/public"
<Directory "c:/apache/htdocs/sortedsounds/public">
AllowOverride All
</Directory>
</VirtualHost>
Hmm, i don't have a MAMP/XAMPP install vhost to share but my test server one looks like so: (server name changed)
<VirtualHost *:80>
ServerName test.co.uk
ServerAlias www.test.co.uk
DocumentRoot /var/www/vhosts/test.co.uk/public
<Directory /var/www/vhosts/test.co.uk/public>
Options -Indexes FollowSymLinks -MultiViews
AllowOverride All
</Directory>
</VirtualHost>
Your .htaccess file is sitting within the /public folder right?
That went well. Cleared down the htdocs folder. Now when I run composer create-project laravel/laravel your-project-name --prefer-dist I get "php is not recognized as an internal or external. Truly truly had enough. Shouldn't be this hard.
OK the excruciating journey continues. Hosed everything and went the WAMP server route. Ran composer to install Laravel to MyDomain folder. No errors reported. I enabled mod_rewrite in httpd.conf . Went to MyDomain root in the browser and got 'Whoops ... '
I'd love to be able go into work on Monday and say 'Hey guys, I was playing around with an awesome new PHP framework this weekend. Something tells me that's not going to happen.
Oh and Chrome tools tell me the Whoops is in fact a 404 not found. Hey ho.
sparkietm said:
OK the excruciating journey continues. Hosed everything and went the WAMP server route. Ran composer to install Laravel to MyDomain folder. No errors reported. I enabled mod_rewrite in httpd.conf . Went to MyDomain root in the browser and got 'Whoops ... '
I'd love to be able go into work on Monday and say 'Hey guys, I was playing around with an awesome new PHP framework this weekend. Something tells me that's not going to happen.
Oh and Chrome tools tell me the Whoops is in fact a 404 not found. Hey ho.
Can you check the bottom of your /storage/logs/laravel.log and see what error is being reported there?
Sorry to hear you're having problems, initial set up can be a bit messy, especially on Windows. I've had no trouble getting it to work with XAMPP a while ago with (roughly) the following steps:
Good call, there's this in the log.
[2014-05-10 22:25:50] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\wamp\www\sortedsounds\bootstrap\compiled.php:5289
Would that kill routing?
sparkietm said:
Good call, there's this in the log.
[2014-05-10 22:25:50] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\wamp\www\sortedsounds\bootstrap\compiled.php:5289
Would that kill routing?
That's the error I see when I don't have a matching route, do you have routes set up?
Looking at routes.php I'd say you should be able to get hello out of the box, no?
Route::get('/', function() { return View::make('hello'); });
i.e domain route maps to hello?
Is there a config setting somewhere to enable pretty URLs?
Have you changed your original virtualhost (from the post about 9 hours ago)? As that is pointing at a different directory than the exception error you just posted.
Pretty URLs are enabled by the mod_rewrite extension being enabled in PHP, if it's not on - you need to enable it and restart Apache.
OK progress. Looks like I'm not quite there on my understanding of doc root and server root...
If I navigate to localhost I get " You have arrived" (calm down it's just a PHP framework :) If I go to localhost/MyDomain I get Whoops.
So do I need a virtualhost entry for MyDomain?
Anyway, on that minor success I'm off to bed. Weekend hasn't been a complete washout, then. Thanks large for your help, guys.
You don't need a virtualhost, but if you're going to develop more than one site/project it is a good idea. If you changed the server root, you've essentially made "localhost" point into that one Laravel project.
I would suggest pausing, and reading up on VirtualHosts:
To answer AndrewBNZ, yes, I did a reinstall using WAMP so the earlier exception is out of whack. Still not quite sure what the httpd.conf documentroot value should be.
My local setup is
c:/wamp/www/sortedsounds/
I'd like my Laravel routing engine to see this as the base url or domain root.
Looks like I'm getting there, though.
Thanks again. We'll pick this up tomorrow :) Must ...... sleep......
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community