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):
- Only for public repository. Unless your provider gives ssh access so you can do public key authentication, private repository is not accessible.
- No composer support. Unless your provider gives access to php-fpm there is no easy way to run
composereven if you managed to install it. So what I do is copying the whole
vendordirectory 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 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
Hope this help you 🍻