I am new to laravel. I am using Ubuntu 15.04. I installed Laravel Framework version 5.1.7 (LTS) using composer and a lamp server using $ sudo apt-get install lamp-server^
command (I didn't install Homestead). I am using PhpStorm 8.0.3
as IDE.
I created three routes and a controller. The PagesController.php
file looks like this:
class PagesController extends Controller
{
public function index()
{
return 'Welcome to my homepage!';
}
public function about()
{
return 'Learn a little about me.';
}
public function hello()
{
return 'Hello World!';
}
}
and the routes.php
looks like this:
Route::get('/', 'PagesController@index');
Route::get('about', 'PagesController@about');
Route::get('hello', 'PagesController@hello');
Whenever I go to http://localhost:63342/my-first-app/public/
(or http://localhost:63342/my-first-app/public/index.php
) it works fine and shows me the Welcome to my homepage!
message. But whenever I go to http://localhost:63342/my-first-app/public/hello
or http://localhost:63342/my-first-app/public/about
, what I get is 404 Not Found
message.
Also, the .htaccess
file which is located at my-first-app/public
looks like this:
<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>
What I have tried:
- I tried
http://localhost:63342/my-first-app/public/index.php/hello
orhttp://localhost:63342/my-first-app/public/index.php/about
but it doesn't work either. - I entered command
sudo a2enmod rewrite
followed bysudo service apache2 restart
but it doesn't work either. - I tried
composer dump-autoload
but it doesn't work either. I changed
AllowOverride
fromNone
toAll
inapache2.conf
. Now part of it looks like this:<Directory /> Options FollowSymLinks AllowOverride All Require all denied </Directory> <Directory /usr/share> AllowOverride All Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /srv/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
but it doesn't solve the problem either.
Update (7/15/2015):
The result of running php artisan route:list
looks like this:
+--------+----------+-------+------+--------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------+------+--------------------------------------------+------------+
| | GET|HEAD | / | | App\Http\Controllers\PagesController@index | |
| | GET|HEAD | about | | App\Http\Controllers\PagesController@about | |
| | GET|HEAD | hello | | App\Http\Controllers\PagesController@hello | |
+--------+----------+-------+------+--------------------------------------------+------------+