There are some ways to deploy an application made with Laravel. By order of recommendation, follow the options.
The deploy options below are for Laravel 5 . I do not know if they work in other versions.
Setting the DocumentRoot to the / public folder
This is the form recommended by the Laravel team and the safest of all. There is no need to change .htaccess
files, just use the Laravel pattern and you're done. The only thing to do is configure your Apache. In VirtualHosts, point the DocumentRoot
to the public
folder as follows:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/path/to/app/public"
<Directory "/path/to/app/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Using aliases and .htaccess
One way to deploy without touching DocumentRoot
is by using Apache aliases and setting a. htaccess
within the public folder slightly different from the% default%. Using Alias , your VirtualHost would look like this below:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/path/to/apps"
Alias /app1 "/path/to/apps/app1/public"
<Directory "/path/to/apps/app1/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Alias /app2 "/path/to/apps/app1/public"
<Directory "/path/to/apps/app1/public>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
This way you can put multiple applications in the same .htaccess
and separated by directories. For each application, in the DocumentRoot
directory, you would need to set public
as follows:
Application 1:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /app1
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Application 2:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /app2
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your apps would respond to the URLs link and link . Look closely at .htaccess
on line .htaccess
. This is to correct a paging problem for Laravel himself.
Moving the files from the public folder
This is the least recommended way , because it opens up security holes. However, let us go to it. Use at your own risk.
Copy the entire contents of the public folder to the root of your project.
Open the RewriteBase /app2
file in the project root and make the following modifications
From:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
To:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
This solution will allow you to request any file at its root, including the file index.php
. Try accessing ( link ) and you'll see your database connection information there!
You will have to protect all files that you do not want to request directly using .env
. I have not tested, but I believe that this way:
RewriteRule \.(.env)$ - [F]
Again, I do not recommend this solution. Try to get in touch with being a host and ask to point the Document Root of the URL to the public folder. Use at your own risk.