Setup Git autodeploy in shared-hosting cPanel (idcloudhost.com)

Since few months back, I have been using idcloudhost.com for my some of my Indonesia-based clients due to its familiar brand, competitive price, features and speed. All of my projects deployed there are built with Laravel.

In other post, I shared about how to deploy Laravel in shared hosting (in general). But at that time I didn’t notice that idcloudhost.com supported git versioning system (with limitations). I believe nowadays, there are many shared hosting provider support it to. So now I’d like to share one way (there may be other way) to utilize it for Laravel project ?.

⚠️ Before you get hyped, there are few catches/limitations that I experience (may differ with other hosting providers):

  1. Only for public repository. Unless your provider gives ssh access so you can do public key authentication, private repository is not accessible.
  2. No composer support. Unless your provider gives access to php-fpm there is no easy way to run composer even if you managed to install it. So what I do is copying the whole vendor directory to the shared hosting. Unfortunately, I also need to copy the vendor directory again every time new dependencies added and/or new seeder/migration files created (sigh) ?

Ok, here we go.

First, find “Git™ Version Control” menu in your cPanel and go through the simple wizard to create a repo & clone from a public URL.

If you can’t find it than it’s not supported 🙁
Just a straight-forward form

If everything goes well, you should see all your files pulled from remote repository to the configured path from your cPanel File Manager.

Second, after you setup Laravel .env properly and copy vendor directory, create a simple bash script to trigger git pull from remote repo & deploy the latest version. We will run this script automatically using cron job.

# customize this based on your own paths
SRCPATH=/home/user/app # path to your git repo
PUBLICPATH=/home/user/public_html/app # public entry-point for the app. In this example, I use subdomain eg. app.example.com
BACKUPPATH=/home/user/backup # where I store customized index.php

# print the date for logging purpose
/bin/date

# trigger git pull
# for some reason, directly running git binary is prohibited
/usr/bin/uapi VersionControl update repository_root=$SRCPATH branch=master

# laravel migration and cache management
# customize this to suit your need
cd $SRCPATH && /usr/local/bin/php artisan migrate:fresh --seed
cd $SRCPATH && /usr/local/bin/php artisan cache:clear
cd $SRCPATH && /usr/local/bin/php artisan config:cache

# copy public files to public_html path
/bin/cp -Rf $SRCPATH/public/* $PUBLICPATH
/bin/cp -Rf $SRCPATH/public/.htaccess $PUBLICPATH

# replace original index.php with custom one
/bin/cp -f $BACKUPPATH/index.php $PUBLICPATH

Save this file inside your home directory, eg. /home/user/deploy_latest.sh then call it from a cron job (adjust the frequency to your need). I’d also suggest piping the output to a log file for eg. /home/user/deploy_latest.log  debugging purpose:

*/5 * * * *	/bin/bash /home/user/deploy_latest.sh > /home/user/deploy_latest.log

That’s it!

Hope this help you ?

Reference

  1. https://forums.cpanel.net/threads/is-there-a-way-to-automatically-pull-from-github.632641/#post-2575985

 

 

 

5 1 vote
Article Rating
yohanes.gultom@gmail.com

Share
Published by
yohanes.gultom@gmail.com

Recent Posts

Get Unverified SSL Certificate Expiry Date with Python

Getting verified SSL information with Python (3.x) is very easy. Code examples for it are…

3 years ago

Spring Data Couchbase 4 Multibuckets in Spring Boot 2

By default, Spring Data Couchbase implements single-bucket configuration. In this default implementation, all POJO (Plain…

4 years ago

Firebase Auth Emulator with Python

Last year, Google released Firebase Auth Emulator as a new component in Firebase Emulator. In…

4 years ago

Google OIDC token generation/validation

One of the authentication protocol that is supported by most of Google Cloud services is…

4 years ago

Fast geolocation query with PostGIS

If you need to to add a spatial information querying in your application, PostGIS is…

4 years ago

Auto speech-to-text (Indonesian) with AWS Transcribe and Python

Amazon Web Service Transcribe provides API to automatically convert an audio speech file (mp3/wav) into…

5 years ago