Skip to content

Instantly share code, notes, and snippets.

@erfg12
Last active January 11, 2022 20:53
Show Gist options
  • Save erfg12/3b05c26cf9ff054d578fcb1e75adfa47 to your computer and use it in GitHub Desktop.
Save erfg12/3b05c26cf9ff054d578fcb1e75adfa47 to your computer and use it in GitHub Desktop.
cpanel git commit to public_html
---
deployment:
tasks:
- export DEPLOYPATH=/home/ACCOUNT/public_html/
- /bin/cp -u -r * $DEPLOYPATH
- /bin/cp .htaccess $DEPLOYPATH
start /b "C:\Program Files\PuTTY\pageant.exe" C:\Users\MY_ACCOUNT\.ssh\ida_rsa.ppk

BENEFITS

  1. Push to multiple locations for immediate reduntant backup.
  2. Accidental file deletions can be restored quickly.
  3. Code history is added.
  4. Option to use more IDEs like Atom or VSCode.
  5. Multiple developers can work on the same files.

SETUP

  1. (OPTIONAL) Setup a private PHP server. LAMP, WAMP or MAMP are great local hosting solutions.
  2. Download git-fork (GIT client with GUI) and WinSCP (FTP client). Or, pick your own git and ftp client.
  3. Download PuTTY (if on Windows). Use PuTTYGen to generate a private/public key and a .ppk file on your workstation computer. Place files in the %USERPROFILE%/.ssh folder.
  4. Go to cPanel and enable jail shell access on your account.
  5. Upload your private/public keys to SSH Access > Manage SSH Keys on your cPanel account. Also click Manage > Authorize.
  6. In cPanel click GIT. Toggle off the clone from URL option, and type in a git repo name and directory name.
  7. Use Putty and SSH in to your server to test if you can gain access, and press Y to accept the certificate. Ex: ssh://[email protected]:22
  8. Now use git-fork to clone your repo into your private PHP server's public_html folder using ssh://[email protected]:22/home/ACCOUNT/REPO_DIR
  9. Use WinSCP and SFTP in to your public_html directory and copy the files to your newly cloned local workstation repo directory.
  10. Make a .cpanel.yml file (see above) in our git repo directory. This file will make our server make a copy of our updated files to our public_html directory.
  11. At this point if you would like to make a second commit to a remote repo do it now with this tutorial.
  12. In git-fork stage our changed files, commit, and push them to the server(s).

At this point our files are now stored in a repo directory, and changes are sent to our public_html folder. We can also test our files prior to commit/push on our local server (step 1).

If you're using Windows and want to use your SSH key at all times for things like VSCode and Atom, I recommend setting up Pageant to start when your computer starts. To do this, open your %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup folder and make a batch file (see above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment