I was trying to setup version control using the NameCheap cPanel Git option to connect to a GitHub repo through SSH. But it kept saying I did not have permissions. I had SSH setup, but it still was not working.
There was a lot of documentation and videos on how to do this, but I thought there must be a better way. That is when I found out about GitHub Actions.
Using cPanel's Git it not a great way to version control your code. A better way is to use GitHub Actions and Secrets. This keeps all the configurations in GitHub instead of relaying on cPanel's Git setup.
Here is the process for connecting your FTP to GitHub Actions:
- Create FTP access in your cPanel that will open in your project folder, like you would for general FTP files access. If you are working with WordPress on theme folder, you would set the FTP directory to that theme folder so it will mirrors you local git repo.
- Create your GitHub repository and go to that repo's "Settings" tab. To see how to setup a GitHub repo checkout my Git Techniques and Shortcuts post.
- In the left sidebar, click Secrets > Actions.
- On the top right, click on "New repository secret".
- Your going to add three secrets use the same values you would for any ftp connection. You can name them something like:
FTP_SERVER
FTP_USER
FTP_PASS
- Click Add secrets.
- Now that the actions are created we need to setup the automated workflow by going to the "Actions" tab.
- Click "New Workflow" > "setup a workflow yourself". This will create a main.yml file for you.
- Replace the generated code with this example code from FTP Deploy
- Now replace the server, username and password at the bottom with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USER }}
password: ${{ secrets.FTP_PASS }} - You Can leave the rest as is unless you want to use a specific branch.
- Click Commit.
- It will create a workflow folder and main.yml file inside your repo so you will need to pull to your local git repo to merge updates.
- Now all you have to do is make your local changes and push updates to GitHub and the workflow actions will update your ftp files on your server.
This works like a regular FTP connection and auto deploys your updated files for you. This way you can build locally and let GitHub action update your files for you.
This is not a complete version control setup so you will need to delete old server files from time to time to keep you things clean.