I 'think' I have successfully installed Laravel using 2 different internet guides. Here is one one of them
http://phpraxis.wordpress.com/2014/07/04/getting-started-with-laravel-4-on-ubuntu-installation-and-configuration/
I have managed to get the include laravel test page "You have arrived"
I am now unable to add an additional route. This is what I did in the routes.php file
|
*/
Route::get('/', function()
{
return View::make('hello');
});
Route::any('foo', function()
{
return 'Hello Andrea';
});
If I add a page foo or foo.php I get the error
Not Found
The requested URL /foo was not found on this server.
I can alter the code in the default view
However if I do something like this
Route::get('/', function()
{
return 'Hello Andrea';
});
everything is fine
I'm confused. I don't think I get Laravel views. how would I fix this to work as a first step on my jourmey
Route::any('foo', function()
{
return 'Hello Andrea';
});
Some guides also suggested putting Laravel in the home folder e.g. /home/username/laravel and whan I tried this I couldnt even get the 'you have arrived page'
I thought Laravel had a shallow learning curve? It must be me.
Thanks for any help
Edit
Ihave found a page that says that conf.d in the PHP file is the old way and it should only be on the other directories on the same level~: apach2 and cli, and now you make the sym link in apache2 and cli. Any opinions much appreciated?
Thanks
You need to make sure that you have mod_rewrite for Apache on and you have in your public folder the following .htaccess file (Laravel defaults):
<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>
go to the httpd.conf file of the server and remove hash from line showing below
LoadModule rewrite_module modules/mod_rewrite.so
Related
I created an index.php file in my public folder (Laravel), an API route in my route/api.php with the url 'submit' and request method post, and a Controller with a function submit() that is executed on the API call.
I tried testing the route on Postman with the following url:
http://mysite.local/api/submit
This was tested as a POST request, but for some reason it keeps returning the index.php file.
I even added a return "Test"; at the start of my submit() function in my Controller to see if the problem was with the code within the function (hope that makes sense, working on my terminology).
But yet again, when I test the API on post man, it still returns the index.php.
Here are my route and Controller:
route/api.php
Route::post('submit', 'SubmitFormController#submit');
// I've also tried the following:
// Route::post('submit', 'App\Http\Controllers\SubmitFormController#submit');
SubmitFormController.php
class SubmitFormController extends Controller {
public function submit() {
return "Test";
/** .. More code below .. **/
}
}
I even tried changing return "Test"; to return json_encode(['test' => 'testvar']); thinking it would help. But Postman still returns the index.php.
My guess is that it's treating my API route as a "directory", but I may be wrong.
UPDATE: I noticed another strange (strange to me) thing happening.
So, when I go to my local host, which is mysite.local, it takes me to my index.php file in my public folder, which is what it should do. HOWEVER, when I then type in something like mysite.local/skjah/asjdklasjd/asjdklasj (which is clearly gibberish and not an actual directory), it redirects to index.php every single time.
So I'm assuming that because api\submit is not a directory in public, it just redirects to index.php. But I'm not sure why as this has worked in the past and my .htaccess has been untouched.
Hope this bit of information helps.
UPDATE: Just been fiddling with the code and noticed that the issue lies in my .htaccess as some of you have pointed out. Here is my .htaccess (straight out of the box when I made the project, didn't touch it).
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I changed the line RewriteRule ^ index.php [L] to RewriteRule ^ index123.php [L] just to see what would happen and the API call to my route function no longer works. Which tells me it has something to do with this file.
That's as far as I got and still looking for a solution. Hope this helps clarify the problem.
My user cant comment yet, so .. here it goes as a answer ...
By and large whenever this occurs it is some page server (this case apache) configuration issue, not php.
Considering you mentioned "routes" I assume you are using "
Have a look in your httpd.conf (and in the .htaccess) if you have something like the configuration below which would be missing or misconfigured (PS: time per time they change configurations, verify if the files in your configuration are compatible with the systems you are using - apache version and php version)
# PHP5 module
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
PS: API Calls (if using 80 or 443 port) should not work as well in this computer, if they do it tends to be misconfiguration on .htacces files.
Found the issue!!
I was trying to access a "customer" table in my controller and other files, when the actual table name is "customers".
GIANT FACEPALM
Hopefully this will help someone, check the spelling in your code before you end up stressing like me Haha.
I'm experiencing some unexpected behaviour in my laravel (4.2) routes.
Let's say my server is available at https://example.com. If I enter https://example.com/whatever/index.php I would expect laravel to throw a NotFoundHttpException, because a route to "whatever" is not defined. Instead laravel shows me the start page, indicating that my "home" route was catched.
If I solely enter https://example.com/whatever everything is fine (i.e. I get the NotFoundHttpException as expected). I neither have the problem on my localhost. Here https://localhost/laravel/whatever/index.php throws the NotFoundHttpException as expected.
My routes.php file:
// Home
Route::get('/', array( 'as' => 'home', function() {
return View::make('home');
}));
Maybe someone can give me a hint where to start searching what's causing that behaviour: Apache config, PHP config, Laravel config?
Ammendment as answer to S. Safdar:
At first I thought of a .htaccess redirect issue, too. In laravel's public folder (the web servers root dir) lays a .htaccess as follows:
<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>
As you can see, the redirect here is handled correctly. The requested "whatever/index.php" is no real file therefore it is redirected to be handled by laravels index.php. If I remove the Rewrite Conditions (plus Rule) I get a regular apache 404 error page. In my case that's of no help as I want laravel to correctly(!) handle all error pages. But for some reason laravels home route matches every url ending on /index.php.
It seems this issue is present with both nginx and apache servers. A few steps I took to mitigate the issue with apache:
Change the index.php filename:
public/index.php to public/start.php
Change .htaccess to read:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ start.php [L]
Change the reference to index.php in the server.php file to have:
require_once $paths['public'].'/start.php';
why not you your route use this like?
// Home
Route::get('/', function() {
return View::make('home');
}));
i think problem is coming from as that you used in your route array.
I am using the php server file for local development temporarly. I use localhost:8888 for my laravel application as this:
php -S localhost:8888 server.php
Laravel loads, I can create new Routes etc.. But unfortunatly I seem to be unable to load any CSS files from the public folder.
Since the other similar questions on stackoverflow seem to include .htaccess file, here is mine from the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
Options +FollowSymLinks
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And this is my Route:
Route::get('/about', array('as'=>'about',function()
{
return View::make('bootstraped');
}));
This is my 'blade' attempt to load the file:
{{HTML::style('css/main.css');}}
Which is printed as a proper link..
This is my php template attempt (I have also tried putting public before css (no luck)
<link rel="stylesheet" href="<?php echo asset('css/bootstrap-theme.css');?>" type="text/css">
And this is the console output in chrome:
GET http://localhost:8888/css/bootstrap.min.css
about:23 GET http://localhost:8888/css/main.css
about:25 GET http://localhost:8888/css/bootstrap-theme.css
about:27 GET http://localhost:8888/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js
about:95 GET http://localhost:8888/js/vendor/bootstrap.min.js
about:97 GET http://localhost:8888/js/main.js
I have sett correct rights for storage folder and tried 777 on public folder..
Theres a couple of things here. Read this link!
PHP's built in server doesn't use htaccess to my knowledge. Also you are executing server.php from outside your actual webroot. So you will need to need to specify the proper webroot.
Goodevening all programmers!
A few days ago, I buyed a domain + hosting. I had made a local project with Laravel 4.2.x, and I wanted to switch it to my online-server. I noticed that I needed PHP version 5.5 for running this version of Laravel, so I changed this in my .htaccess file.
All seems to be correct now, but it isn't correct jet. De links (href) to other pages won't work! Every time I routed to a URL without the '/' URI, I got an error page wich says that the server can't find this document.
My files:
// routes.php
<?php
Route::controller('/', 'PageController');
//Route::get('/', 'PageController#getIndex');
//Route::get('/contact', 'PageController#getContact');
PageController.php
<?php
class PageController extends BaseController {
protected $layout = 'master.master';
public function getIndex() {
return View::make('pages.index');
}
public function getContact() {
return View::make('pages.contact');
}
}
And my views: Everything is correct because it is possible to access the contact page at the '/' URI, but I just can't access pages at other URI's.
Thanks in advance!
Your code is fine, but routing is case sensitive. So http://example.com/Contact is not the same as http://example.com/contact
The first one (upper case C) should fail with a "Controller method not found" error. The second one (lowercase c) should work.
If it is not a case sensitivity issue, then your .htaccess file is not correct, missing, or unsupported on your web host. Here is an example of a know good .htaccess 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>
I have been spending hours on this issue and hope to find my way out. I have set up laravel correctly, created a project myapp
My route.php file just contains
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/users', function()
{
return 'Users!';
});
When I run
http://localhost/myapp/public/
I get the laravel start page correctly
When I run
http://localhost/myapp/public/users
I get
The requested URL /myapp/index.php was not found on this server.
I don't know why its looking for index.php.
When I run
http://localhost/myapp/public/index.php/users
I get a page with text "Users". I should obtain this page when running
http://localhost/myapp/public/users
instead.
Below is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
Rewritebase /myapp/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Any ideas? Am running a Apache on Linux.
Your RewriteBase is set to /myapp/ but your index.php file is in /mayapp/public/ is it not?
As such, I think you'll find the RewriteBase needs to be /myapp/public/.
Make sure you have mod_rewrite enabled on apache web server.
Make sure that your vhost config allows and parses htaccess files
Just do this and try to restart the apache.
sudo a2enmod rewrite
To restart apache: sudo services apache2 restart
I ran into same problem with production server, nothing seemed to work, no chmod/s no other solution but adding a simple line to .htaccess worked.
RewriteBase /
Thanks to the thread and user odaria
In your application/config/application.php file change:
'index' => 'index.php',
to:
'index' => '',
That should tell laravel not to use index.php and to rewrite correctly.
It works with standard .htaccess file which comes with laravel (haven't checked if you modified it)
Use this re-write rule:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /my_app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Also, in `application/config/app.php' change:
'index' => 'index.php'
to
'index' => ''
The quickest way is to add a symbolic link in command line:
ln -s your/acutal/path/myapp/public app-dev
Now browse http://localhost/app-dev should work fine as well as all the routes. You can change app-dev to whatever you want as the name.