Laravel deployment on shared hosting via GitHub

How properly deploy Laravel application on HostBrook or GoDdaddy Linux shared hosting.
Written by Admin Last update: July 22, 2021

The benefits of app deployment via GitHub:

  • Easy update of your application
    (if coding was changed or new functionality was added)

  • Easy update of Laravel and dependieces

  • Possibility to work on application in team

Laravel

Before following the steps below be sure you have uploaded your Laravel project at the GitHub repository.

Article summary:

Step 1. Get SSH access to your hosting #

You have two options to get access to your cPanel command line:

  1. Via terminal emulator, like PuTTY

    Note: Do not forget to enable SSH at the server settings of your account:
    Manage WebHosting -> Dashboard -> Settings -> tab "Server" -> SSH access -> Manage

  2. Using online interface in the cPanel:
    cPanel Admin -> section "Advanced" -> Terminal

Step 2. Composer installation #

By default, Composer is pre-installed on HostBrook and GoDaddy hostings, but you do not have a possibility to update to the newest version because you don't have root permissions at the shared hosting plans. But this is not a problem at all. By the link below, we explain how to install Composer locally, just for your cPanel account:

Composer installation at cPanel

Step 3. Check PHP version and required extensions #

Laravel 8 requires version PHP 7.3+
Use next command in terminal to check the current PHP version

php -v

If version is incorrect - change it to newest in the cPanel

cPanel -> section "SOFTWARE" -> "Select PHP Version"

and here select the version from the droplist. Also at this page be sure the next PHP extensions are enabled:

- BCMath PHP Extension
- Ctype PHP Extension
- Fileinfo PHP extension
- JSON PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PDO PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension

or just checking this using the next command in terminal:

php -m

Step 4. Create the application folder #

The home directory for Laravel project needs to be /[YOUR_APP]/public therefore you need to change default home directory (document root) from ~/public_html/ to something like for example ~/[YOUR_APP]/public

Lets start with creating Laravel application folder in the home:

cd ~
mkdir [YOUR_APP]

The next step depends on domain type, so there are different way you can do it:

For Main Domain:

For the main domain you can not change default pointing to document root ~/public_html/ therefore you can easly replace the ~/public_html/ folder with a symbolic link to ~/[YOUR_APP]/public

First, delete the existing folder ~/public_html/ and next create a symbolic link to your application:

cd ~
rm -r public_html
ln -s [YOUR_APP]/public public_html

So, now the folder ~/public_html/ is asociated with Laravel folder ~/[YOUR_APP]/public

For Subdomain

Go to: cPanel Dashboard -> section "DOMAINS" -> Subdomains

Here click a pencil icon to edit a document root

For Addon Domain

Go to: cPanel Dashboard -> section "DOMAINS" -> Addon Domains

Here click a pencil icon to edit a document root

Step 5. Configuring Git #

Step 6. Setup the app #

Was this article helpful?

Related articles