Laravel 5 Virtual Host for an Apache Subdirectory
May 5, 2015  

I ran into a situation at work the other day that required Laravel be installed in a subdirectory. I personally prefer Nginx, but their production server is running Apache, so I created a staging environment that would mimic production.

Before we get into it, I want to say that you're better off using something like Homestead for development and Laravel Forge for production. Also, where possible use subdomains instead of subdirectories. This just wasn't the case here.

/etc/httpd/conf.d/eradmin.conf

In the code below be sure to change ServerIP to your actual server's ip address (ex: 105.232.18.62).

<VirtualHost *:80>
  ServerName ServerIP
  Alias /eradmin /var/www/eradmin/public
  DocumentRoot /var/www/eradmin/public
  <Directory "/var/www/eradmin/public">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

/var/www/eradmin/public/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /eradmin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

If you my server IP was the example used above, the result would be http://105.232.18.62/eradmin.