Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GrzegorzWalewski/93a2ed7f60a37e29ae4f99da119383cc to your computer and use it in GitHub Desktop.
Save GrzegorzWalewski/93a2ed7f60a37e29ae4f99da119383cc to your computer and use it in GitHub Desktop.
Laravel "test" deploy to shared hosting server

When to use?

Use this when deploying your app to shared hosting where You can directly access apache virtual hosts.

How to deploy

  1. Go to Your public_html dir (the main dir of your domain) - hosting provider usualy puts here sth like default.php or index.php - delete this and any other files that are there.
  2. Clone Your repository directly to the directory:
git clone git@github.com:Vendor/ProjectName.git .

(the dot at the end specifies that You want files to be downloaded directly to the dir You are currently in)

  1. Create new file server.php with content:
<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';
  1. Create .htaccess file with content:
Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} www.jaksmakowalo.pl
RewriteRule (.*) https://jaksmakowalo.pl/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.ico|\.css|\.js|\.png|\.gif|robots\.txt|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.otf|\.pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(login|uploads|assets|css|js|images|ca|favicons|fonts|)/(.*)$ public/$1/$2 [L,NC]


RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
  1. Check if You have composer installed: composer -v (version 2 is prefered)
  • if non (or version 1.x is installed) you have to install newer version: Official composer install instruction
  • Depending on how You installed composer you may use composer -v or php composer.phar -v to check version again ;)
  1. Copy .env.example to .env: cp .env.example .env and configure Your project (db connection, project name other connections)
  2. Run composer install or php composer.phar install
  3. php artisan key:generate
  4. Migration: php artisan migrate
  5. Seeders php artisan db:seed
  6. Now we need to install node.js (npm) - You may skip this if npm -v returns npm version
  1. Run npm run build

Your project should be up and running :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment