I'm not only new to Laravel 4, but new to using frameworks. I thought I'd start with Laravel since it's gotten such good reviews.
I've got a good install of Laravel. I go to /l4/public and see the welcome page.
I'm trying to add a route to routes.php so that when I navigate to /l4/public/articles I get a response.
I get "The requested URL /l4/public/articles was not found on this server." Do I need to run an artisan command to compile the routes? It's probably something easy. Why this message?
routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('articles', function ()
{
//return View::make('articles');
return "Articles hello there";
});
Problem is solved by two editing changes in apache's httpd.conf file.
AllowOverride None is default. AllowOverride controls whether .htaccess files are processed.
mod_rewrite is commented out by default.
Changes to make:
Change 1: Activate mod_rewrite by uncommenting it.
Change 2:
Change
AllowOverride None
to
AllowOverride All
Now restart Apache...
The default .htaccess file that Laravel provides in the public folder specified some mod_rewrite rules. These rules were not getting applied because AllowOverride was set to none. Be sure and restart apache after changing these settings.
My configuration: Apache 2.4.6 on Windows XP.
It appears that there may be some security implications to the AllowOverride change. If anyone has additional information on this, I would like to hear it.
That Error basically say that the router cannot found your request. Make sure you already save your changes.
if you using the artisan command to running the page,just re-run again command "artisan Serve".
You need mod_rewrite on. Try: l4/public/index.php/articles
in httpd.conf change
<Directory />
AllowOverride none
Require all granted
</Directory>
to
<Directory />
AllowOverride all
Require all granted
</Directory>
then uncomment
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
Related
I try to install my Laravel application in a new environment acceptance,
After composer install (no errors)
when I check the url it's redirected to /login which is normal
The problem: it returns 404 error and this error is coming from the server not from Laravel because I customized 404 error in my application
it seems like the server does accept only / path :
also when I change the router :
from
Route::get('/', function () {
if (Auth::check()) return redirect('/myprofile');
return redirect('/login');
});
To this:
Route::get('/', function () {
return 'hello world'
});
it works and I can see hello world
the route /login exists when I route:list
First check if Apache's mod_rewrite module is enabled, If it's not enabled aleady please run below commands to enable it or else jump to second part of the answer
sudo a2enmod rewrite
sudo service apache2 restart
Also add below config block in your virtual host configuration to enable laravels .htaccess rules
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Change /var/www/ path accordingly
I made route, but apache server cant see that route. There no problem with Laravel welcome page but when I try to make another folder in view. Apache cant see that page. 404 not found pop up.
Here is the Route and the Controller codes
Route::get('/pages', 'Pages#index');
and controller
function index(){
return "test";
Also my httpd my document root: /var/www/html/laravel/public
module dir:
DirectoryIndex index.html index.php
Do I need to change something else too? to make this route accessible?
in centos 7, None --to-> All makes it fine.
<Directory /var/www/html>
. . .
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None --> All
. . .
</Directory>
I have a Debian server 9 with Apache 2 and Laravel 5.6
I have the folder: /LcmTI/projects/www to publish my projects, port 81 answers for all projects, eg:
http://localhost: 81/project1 [html project only]
In the folder /LcmTI/projects/laravel, I have two laravel projects 5.6:
extranet at /LcmTI/projects/laravel/extranet
intranet at /LcmTI/projects/laravel/intranet
I have created a link to the two projects in the www folder (which is the folder that is published):
ln -s /LcmTI/projects/laravel/extranet/public /LcmTI/projects/www/extranet
ln -s /LcmTI/projects/laravel/intranet/public /LcmTI/projects/www/intranet
In this way, I expected without any problem to access the two laravel environments without any problem, but it is not working.
When I type:
http://localhost:81/extranet/api/test or http://localhost:81/intranet/api/test
does not work and should return:
/* file routes/api.php in both applications */
`Route::get('test', function () {
return response()-> json(['foo' => 'bar']);
});`
If I enter http://localhost:81/extranet or http://localhost:81/intranet
Enter the homepage of Laravel
My configuration for Apache 2:
<VirtualHost *:81>
DocumentRoot /LcmTI/projects/www
<Directory /LcmTI/projects/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
I'm having a hard time setting up larval API applications on a single host.
I'm beginning Laravel 5.2 and I'm stuck with this simple route:
Route::group(['prefix' => 'admin'], function(){
Route::get('/', function(){
return view('admin/login');
});
});
When I type http://<my_site>/admin I am redirected to http://<my_site>/public/admin/? instead of returning the view (I also tried with a simple return 'ok' and it keeps get redirected.
I can't understand where I am wrong, please a help?
EDIT: I found out that it's because I have an admin folder in my public one, that maybe causes conflict! But I'd like to keep the name admin to my assets folder, what can I do?
You should set up public directory as root direcotry in your web server configuration. For example, for Apache do this:
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
The thing is if your web server is pointed to another directory (for example, the Laravel's root directory), your app will never work properly.
I have a ruby on rails application that is located at /home/user/application. I have a Apache webserver whose DocumentRoot is /var/www. And I have a symlink /var/www/application -> /home/user/application.
My apache configuration section that concerns the ruby on rails is the following:
RailsBaseURI /application
<Directory /home/user/application>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
I modified the Passenger code so in the very beginning of it spawning it would print (to a file) the option app_root. If it matters, I modified the file phusion_passenger/spawn_manager.rb in the method handle_spawn_application.
The value that I get is /home/user and this is wrong, I needed /home/user/application. So my question is, how does Passenger figures out the option['app_root'] (which becomes RAILS_ROOT|Rails.Root)?
Observation: I modified the Passenger code to hardcode app_root to /home/user/application and everything worked fine.
Change the symlink so that /var/www/application points to /home/user/application/public
Then just change RailsBaseURI to RackBaseURI and undo your changes to spawn_manager.rb
Previous discussion assumed single application.
<Directory /var/www/application/public>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
See the Apache Phusion documentation.
You need to add DocumentRoot and append /public to your Directory config and undo your changes to spawn_manager.rb.
As you noticed, the app_root is one directory up from what is specified.. The parent directory of /home/user/application/public is /home/user/application which is the Rails root.
You want RackBaseURI instead of RailsBaseURI for Rails > 3
The reasoning behind this is so that Apache serves the static assets (which are in the public directory) and then if that isn't present Passenger routes the request to the Rails app.