I installed Lumen on my web server, but I have problems with routes
// http://12.345.678.910/
$app->get('/', function() use ($app) {
return "This works";
});
But in this second case he cant find directory
// http://12.345.678.910/api
$app->get('/api', function() use ($app) {
return "This dont work";
});
In second case I am getting standard 404 error.
The requested URL /api was not found on this server.
I use Apache, Ubuntu, PHP 5.5 and Lumen
It sounds like your URL rewriting isn't working. If you add index.php
to the URL right before the /api
does it work?
For example, yourdomain.com/api
would become yourdomain.com/index.php/api
and if the second URL works, then rewriting isn't working.
If your rewriting isn't working, but you have the .htaccess
file in your public
directory, then you probably need to allow overrides in your Apache configuration. Here is an example virtual host configuration for Lumen on Ubuntu.
I've marked the lines you need to change. Change the first and third to point to the public
directory in your website's directory. Then change the second line to the domain name you're using with your website.
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
AllowOverride All # This line enables .htaccess files
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You'll need to restart Apache for these settings to take effect.
Enabling the .htaccess
file should work, but using .htaccess
slows down your site some. The best solution is to put the contents of the .htaccess
file in your virtual host, and then disable .htaccess
files.
The example virtual host configuration for that looks like this:
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<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>
</Directory>
</VirtualHost>
Once again, you'll need to restart Apache for these settings to take effect.
Probably the .htaccess file under public
folder is missing.
Check this: https://github.com/laravel/lumen/blob/master/public/.htaccess
In the root of your application, create a .htaccess
file if its not already there. Then paste the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I assuming that you are using apache
server and have mod_rewrite
turned on.
Read basic configuration section in Lumen documentation.
If you are unsure how to turn on mod_rewrite
, this stackoverflow post might help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With