Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy laravel + vuejs to shared hosting

I am having problems deploying my laravel + vuejs application to shared hosting account, I am aware of other efficient ways such as cloudways but I just want to test my site out.

I have tried with some free hosting but always wrong, do I need to upload all my node_modules through ftp for the vue components to work? it is large and takes plenty of time.

I have checked alot of tutorials on this but none has deployed laravel with vuejs to server, any guide to to this will be much appreciated.

like image 975
Benedictgeek Avatar asked May 07 '19 13:05

Benedictgeek


People also ask

Can I deploy Laravel on shared hosting?

Developers opt to deploy Laravel on shared hosting mainly for cost savings. Shared hosting is cheap and is generally preferred by those unaware of its detriments. Similarly, developers generally install and deploy Laravel to shared hosting without considering the problems it causes for the end-users.


1 Answers

  1. Go into the laravel-vue project and build the production version of the app.

  2. Make sure that hidden files are visible then compress everything but the node_modules

  3. Go to your cpanel, create a folder for your new app in the root (not public_html)

  4. Upload and extract the compressed file into the new folder you just created

  5. Move the content of the public folder except .htaccess into the root of the new folder you just made

  6. 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>
  1. Edit the index.php file in this same folder by changing:

    • require __DIR__.'/../vendor/autoload.php'; to require __DIR__.'/vendor/autoload.php';
    • require_once __DIR__.'/../bootstrap/app.php'; to require_once __DIR__.'/bootstrap/app.php';
  2. 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.

like image 177
Willower Avatar answered Sep 19 '22 13:09

Willower