Deploy laravel + vuejs to shared hosting
Go into the laravel-vue project and build the production version of the app.
Make sure that hidden files are visible then compress everything but the node_modules
Go to your cpanel, create a folder for your new app in the root (not
public_html
)Upload and extract the compressed file into the new folder you just created
Move the content of the
public
folder except.htaccess
into the root of the new folder you just made- Create a new
.htaccess
file in the root of this same folder and add these:
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]</IfModule>
Edit the index.php file in this same folder by changing:
require __DIR__.'/../vendor/autoload.php';
torequire __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/../bootstrap/app.php';
torequire_once __DIR__.'/bootstrap/app.php';
Create a subdomain for this app and set the document root to the folder we created and placed all the laravel files into
Visit the subdomain.your-domain.your-tld and the app should work.
Just creating a new .htaccess
file inside your root (public_html
) or any subdirectory (if you're using subdomain) and pasting the following lines will solve your problem.
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]</IfModule>