Make sure you have hosted your project and set up the index.php, env files etc. before you do this. See ‘hosting your project with cpanel’
If you just want to change some files / prefer not to setup this automatic deployment, refer to deployment of changes, and scroll to the section without automatic deployment.
Why automatic deployment:
Deploying from a git repository with c-panel ensures you don’t need to zip/upload files manually. You can completely automate this pull/deploy process with Cron-jobs, but for now I’ll just focus on linking a (hidden) git repository to c-panel. If your git repository is public you can skip the SSH key generation steps
Refer to Guide to Git™ — Deployment | cPanel & WHM Documentation if you run into trouble
Steps
First: create a .cpanel.yml file in the root of your project, which will tell c-panel how to deploy the files in your repository to your front-end and back-end folders.
Example .cpanel.yml file
deployment:
tasks:
- export DEPLOYPATH=/home/aleidsusername/spicemixes.nl
# below 2 steps will only work if your host supports node!
# Otherwise, youll need to build locally, and then commit the build folder
#(which is by default gitignored, for me was around 30 mb)
# Install dependencies (if needed)
#- npm ci
# Build the Svelte app
#- npm run build
# Copy the build folder to the deployment path
- /bin/cp -a public/build/* $DEPLOYPATH/build
- /bin/cp -a public/vendor/telescope/* $DEPLOYPATH/vendor/telescope
- /bin/find public -maxdepth 1 -type f ! -name "index.php" -exec /bin/cp {} $DEPLOYPATH/ \\;
# Copy other folders to the deployment path
- /bin/cp -a app/* /home/alei5901/spicemixes/app
- /bin/cp -a config/* /home/alei5901/spicemixes/config
- /bin/cp -a routes/* /home/alei5901/spicemixes/routes
- /bin/cp -a resources/* /home/alei5901/spicemixes/resources
- /bin/cp -a public/build/manifest.json /home/alei5901/spicemixes/public/build/manifest.json
- /bin/cp -a bootstrap/* /home/alei5901/spicemixes/bootstrap
- /bin/cp -a database/* /home/alei5901/spicemixes/database
- /bin/cp -a composer.json /home/alei5901/spicemixes/composer.json
- /bin/cp -a composer.json /home/alei5901/spicemixes/composer.lock
# below didnt work because contents are gitignored
#- /bin/cp -a storage/app/public/* /home/alei5901/spicemixes/storage/app/public
Info: in my case, I will only auto-deploy the build folder, as e.g. the storage (linked to storage/app/public) folder will have userdata in the future and we don’t want to overwrite this. Also, you usually don’t upload images to github, so they are automatically ignored anyway.
Please note! Npm commands dont work on every server, not on hostinger cpanel silver, so I commented them out here and you’ll need to;
run ‘npm run build’ in vscode before committing changes to compile your build folder.
Then commit your project (optionally to a dedicated deployment branch),
and connect your cpanel git version control with your github repository;