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
Before following the steps below be sure you have uploaded your Laravel project at the GitHub repository.
Article summary:
You have two options to get access to your cPanel command line:
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
Using online interface in the cPanel:
cPanel Admin -> section "Advanced" -> Terminal
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 cPanelLaravel 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
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 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
Go to: cPanel Dashboard -> section "DOMAINS" -> Subdomains
Here click a pencil icon to edit a document root
Go to: cPanel Dashboard -> section "DOMAINS" -> Addon Domains
Here click a pencil icon to edit a document root
Use the next command in terminal to check the current Git version
git --version
if you dont have an SSH key yet configured for this account, you need to generate one.
You can do it either via terminal or cPanel.
ssh-keygen -t rsa -b 4096 -C [cpanel_username]
once done, execute:
cat ~/.ssh/id_rsa.pub
and copy the outputted text to your clipboard, you'll need it in your Git repo settings.
cPanel -> section "SECURITY" -> "SSH Access" -> Manage SSH Keys -> Generate a New key
copy the generated text to your clipboard, you'll need it in your Git repo settings.
Go to your application repository at GitHub.
Go into Settings Tab -> Deploy Keys in the left side bar
You should see the message "There are no deploy keys for this repository"
Hit the button "Add deploy key", then paste your public SSH key (from the previous step 5.2) that begins with "ssh-rsa..." and hit the button "Add key".
To clone your application to the hosting folder ~/[YOUR_APP]/
you need to go to the upper folder (in our case it is ~/
) and run the command:
git clone https://github.com/[GIT_USER]/[YOUR_APP] [YOUR_APP]
Go to the app folder and install the dependencies:
cd [YOUR_APP]
composer update
Create new MySQL database, new user (if required) and add User To Database
cPanel -> section "DATABASES" -> "MySQL® Databases" -> Create New Database
Be sure you recorded your database credentials: database name, username and password
Copy the .env.example file to .env
cp .env.example .env
Edit the .env file and configure it with your setting:
nano .env
Few key settings that is important are
DB_HOST=localhost
DB_CONNECTION=mysql
DB_PORT=3306
DB_DATABASE=[DB_NAME]
DB_USERNAME=[DB_USER]
DB_PASSWORD=[DB_PASS]
APP_ENV=production
APP_DEBUG=false
php artisan key:generate
php artisan migrate
Set the permission of the storage folder so that the web server can write to it
chmod -R 775 storage
composer dumpautoload -o
php artisan config:cache
php artisan route:cache