There was a problem loading the comments.

How to Deploy Your Website With Git in DirectAdmin

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Every DirectAdmin plan includes built-in Git feature. You can connect a repository on GitHub, GitLab or Bitbucket and have every git push publish your site automatically, with full version history and easy rollbacks. This guide covers the recommended Git Manager method, pushing straight to your account, and a manual terminal method.

Just want your site online? You don’t need Git. Uploading your files with File Manager, FTP or SSH works perfectly, and is often simpler for a site built with an AI tool.

What You'll Need

  • A web hosting plan with the DirectAdmin control panel (not our legacy Webumake plans).
  • A domain pointed at your hosting account — search for a domain if you don't have one yet.
  • Your AI-generated website files on your computer.
  • A free account with a Git host such as GitHub, GitLab or Bitbucket (recommended, so you can use automatic deploys).

Step 1: Put Your Site Into a Git Repository

First, organize your site's files into a single project folder. Your home page should be called index.php or index.html and sit at the top level of the folder, because that folder will become your site's public_html. A typical layout looks like this:

my-website/
├── index.php
├── about.php
├── contact.php
├── css/
│   └── style.css
├── js/
│   └── main.js
└── images/

Then, from inside that folder, turn it into a Git repository and push it to GitHub (create an empty repository on GitHub first and copy its SSH address):

cd my-website
git init
git add .
git commit -m "First version of my website"
git branch -M main
git remote add origin [email protected]:yourname/my-website.git
git push -u origin main
Keep secrets out of Git. If your AI-generated PHP connects to a database or an API, don't commit passwords or API keys. Put them in a separate file such as config.php, list it in a .gitignore file, and upload that one file to the server separately using DirectAdmin's File Manager.

A simple .gitignore for most AI-built PHP sites:

config.php
.env
.DS_Store
node_modules/

Step 2: Create an SSH Key for Private Repositories

If your GitHub repository is public, you can skip this step. If it's private (recommended for most business sites), your hosting account needs permission to read it. DirectAdmin only supports private repositories over SSH, so you'll use a deploy key:

  1. In DirectAdmin, open SSH Keys and create a new key (or ask our support team to help). DirectAdmin uses the account's default id_rsa key if you don't specify another one.
  2. Copy the public key (the one ending in .pub).
  3. In GitHub, go to your repository's Settings → Deploy keys → Add deploy key, paste the public key and save. Read-only access is all that's needed.

Step 3: Create the Repository in DirectAdmin

  1. Log in to DirectAdmin and go to Advanced Features → GitClick Create Repository.

Enter a Name for the repository, for example my-webs In Remote, paste your repository's address, e.g. [email protected]:yourname/my-website.git. For a private repository this must be the SSH address, not the HTTPS one. Leave Keyfile blank to use the default key, or enter the path to the key you created in step 2. Click Create. DirectAdmin clones your repository into your

Step 4: Set the Deploy Branch and Deploy Directory

Creating the repository stores your code, but it doesn't publish it yet. To it the repository in DirectAdmin and set:

  •  
  • Deploy branch: the branch you want published — usualr projects may use master).
  •  
  • Deploy directory: where the files should go, relative to your home directory. For your main site that's domains/yourdomain.com/public_html. The folder must already exist.
  •  

Save, then click Deploy (or fetch from the remote) and visi AI-built site should now be live.

Back up first. Deploying writes your repository's files into the deploy directory. If there's already a site in public_html, download a copy before your first deploy, and remove the default placeholder index.htmlindex.php.

Step 5: Turn On Automatic Deploys With a Webhook

This is the step that makes Git hosting feel like magic. With a webhook, every git push to GitHub tells DirectAdmin to fetch the new code and deploy it automatically.

  1.  
  2. In DirectAdmin's Git page, open your repository and copy its webhoo
  3. In GitHub, go to Settings → Webhooks → Add webhook.

Paste the webhook URL into Payload URL, choose Jus and save.

Webhooks work for repositories synced from a remote, and they only deploy whand deploy directory are set correctly.

Alternative: Push Directly to Your Hosting Account

Prefer not to use GitHub? If SSH access is enabled on your account, you can push straight to the repository DirectAdmin created. DirectAdmin keeps repositories at domains/yourdomain.com/repo-name.git, and each one runs a deploy h push:

git remote add hosting youruser@yourserver:domains/yourdomain.com/my-website.git                                                                                        git push hosting main

Not sure whether SSH is enabled on your plan, or what your server name is? Contact our 24/7 support team and we'll heget set up.

Manual Method: Clone With the Terminal and Pull on Push

The Git Manager above is the easiest route, but some developers prefer to manage Git by hand from DirectAdmin's Terminal (or an SSH session). This method clonerepository directly into public_html, so it needs one extra securi

 

1. Generate a deploy key on the server

Open the Terminal in DirectAdmin and create a key pair. Press Enter to accept the default location and leave the passphrase empty so automated deploys can use it:

ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub

Copy the output (it starts with ssh-ed25519) and add it as a deploy key — in GitHub under Settings → Deploy keys → Add deploy key, or in GitLab under Settings → Repository → Deploy keys. Thworks (type yes the first time to trust GitHub's host key):

ssh -T [email protected]

2. Clone into your web root

Your site's files live in domains/yourdomain.com/public_html (yectAdmin under System Info & Files → File Manager).Git can only clone into an empty folder, so remove any placeholder files such as the default index.html first, then clone using the SSH address:

cd ~/domains/yourdomain.com/public_html
git clone [email protected]:yourname/my-website.git .

The trailing dot matters: it puts the files directly into public_html< a my-website subfolder.

3. Block public access to the .git folder

Don't skip this. Because the hidden .git folder now sits inside your public web root, anyone who knows to look could download your full source code and commit history — including any passwords the AI may have hard-coded alongto the .htaccess file in public_html (create it if itdoesn't exist):

# Deny access to Git data and environment files
RedirectMatch 404 /\.git
<FilesMatch "^\.(env|gitignore)$">
  Require all denied
</FilesMatch>

Then visit https://yourdomain.com/.git/config in your browser — you should get a "Not Found" page.

4. Add a webhook script for automatic pulls

To update the site on every push, create a small deploy.php in hat runs git pull when GitHub calls it with a secret token. Replace the token with a long random string of your own:

<?php
// deploy.php - pull the latest code when GitHub sends a push webhook
$secret = 'replace-with-a-long-random-string';

if (!hash_equals($secret, $_GET['token'] ?? '')) {
    http_response_code(403);
    exit('Forbidden');
}

$output = shell_exec('cd ' . escapeshellarg(__DIR__) . ' && git pull origin main 2>&1');
header('Content-Type: text/plain');
echo $output;

In GitHub, open Settings → Webhooks → Add webhookURL tohttps://yourdomain.com/deploy.php?token=your-random-string, choose application/json as the content type and Just the push event, and save. Now every git push origin main pulls the new code onto your live site.

 

Note: this script relies on PHP being allowed to run shell commands. If your webhook returns an empty response, use the DirectAdmin Git Manager method above instead — it handles webhooks without any custom script.

5. Or deploy with GitHub Actions

If you'd like GitHub to run checks before anything goes live, a GitHub Actions workflow can log in over SSH and pull the code for you. Save this as .github/workflows/deploy.yml in your repository, and add your servivate SSH key as repository secrets:

name: Deploy to DirectAdmin
on:
  push:
    branches: [ main ]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USERNAME }}
          key: ${{ secrets.SERVER_SSH_KEY }}
          port: ${{ secrets.SERVER_PORT }}
          script: |
            cd ~/domains/yourdomain.com/public_html
            git pull origin main

What if my AI built a Laravel or React app?

Plain PHP, HTML and CSS sites are live the moment the files land — themeworks are different: a Laravel app needs composer install--no-dev (and often php artisan migrate --force) after each pull, and a React or other JavaScript app needs npm run build. The simplest approach is usually to build on your own computer or in GitHub Actions and deploy only the n running heavy builds on shared hosting.

Troubleshooting

"Permission denied (publickey)" when creating the repository: Nothing deploys: make sure the deploy directory already ex name matches exactly (main vs master). The webhook fires but the site doesn't change: check the webhook's recent deliveries in GitHub for errors, and confirm you pushed to the deploy branch. The site shows a blank page or 500 error: usually a PHP erfig.php. Check the error log in DirectAdmin. "Destination path '.' already exists and is not an empty directory": (manual method) public_html still contains files. Move or delete them, then run the clone again. "git pull" fails with merge conflicts: (manual method) someone edited files directly on the server. To throw away those server-side edits and match GitHub exactly, run git fetch origin && git reset --hard origin/main &mdas through Git instead. Old version still showing: clear your browser cache or try a private window.

Rolling Back a Bad Change

If a change breaks your site, undo the last commit and push again:

git revert HEAD
git push

Your daily backups, kept for 30 days, give you a second safety net for files and databases.

 


Share via
Did you find this article useful?  

Related Articles


Comments

Add Comment

Replying to  

© Domain Name Sanity