Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache alias for Laravel and Lumen

I'm trying to make an alias on my server which directs all traffic that comes into example.com/z/ to a different directory than the rest of example.com, where example.com has a Laravel 4.2 install and example.com/z/ has a Lumen install which runs a service.

This is my original vhost:

<VirtualHost *:80>
 ServerName example.com
 DocumentRoot /data/user/public_html/public
 <Directory /data/user/public_html/public>
  Options +FollowSymlinks
  AllowOverride All
 </Directory>
</VirtualHost>

And this is the vhost with the /z/ alias added in:

 <VirtualHost *:80>
  ServerName example.com
  DocumentRoot /data/user/public_html/public
  Alias /z/ /data/user/service/public
  <Directory /data/user/service/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
  <Directory /data/user/public_html/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
 </VirtualHost>

When a navigate to exmaple.com/z/ I get a 403 page and in the logs this error:

 Directory index forbidden by Options directive: /data/user/service/public

And if I go to anything else under /z/ (example: /z/abcd) I get a 404 page, but it looks like the Laravel 404 page instead of the Lumen 404 page.

Any ideas on how I can get this working?

like image 352
Samsquanch Avatar asked Apr 27 '15 16:04

Samsquanch


3 Answers

The message is telling you didn't added the option Indexes

<Directory /data/user/service/public>
   Options +FollowSymlinks +Indexes
   AllowOverride All
</Directory>

Your alias probably will have to be

Alias /z /data/user/service/public

or

Alias /z/ /data/user/service/public/
like image 139
Antonio Carlos Ribeiro Avatar answered Oct 18 '22 21:10

Antonio Carlos Ribeiro


Directory index forbidden by Options directive: /data/user/service/public

Apache has not found file specified by DirectoryIndex - default to index.php index.html and cannot show indexes follow you're configuration Are you sure there is one of this files present in /data/user/service/public ?

Be sure of this and add and .htaccess into you're public directory

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

from http://lumen.laravel.com/docs/installation#pretty-urls

or add a directory block to parent level (if there is some symb link)

  <Directory /data/user>
        Options -Indexes FollowSymLinks
        AllowOverride all
        Order Allow,Deny
        Allow from all
    </Directory>
like image 39
bastien Avatar answered Oct 18 '22 21:10

bastien


Untested, but adding Require all granted should remove some of the sharing restrictions.

The other thing to consider is ensuring your folder is actually owned by Apache's owner (www-data, apache, or even your username or something else depending on your installation). If the folder can't be read by Apache, it will trigger an error.

I also switched the Directory to refer to the Alias rather than the file path.

 <VirtualHost *:80>
  ServerName example.com
  DocumentRoot /data/user/public_html/public
  Alias /z /data/user/service/public
  <Directory /z>
   Options +FollowSymlinks +Indexes
   AllowOverride All
   Require all granted
  </Directory>
  <Directory /data/user/public_html/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
 </VirtualHost>
like image 1
smcjones Avatar answered Oct 18 '22 22:10

smcjones