Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DigitalMasters's avatar

Install and deploy new site via Api (Forge SDK)

Hey guys, i want to create servers, create sites and install a custom git repository via the forge sdk. Now i am stuck with no further idea at installing the git repository.

i tried $forge->installGitRepositoryOnSite with the follwing payload

[
                    'provider'   => 'custom',
                    'repository' => $repoSshUrl // git@,
                    'branch'     => $branchName// feature/xyz,
                    'composer'   => true,
					'deploy_script => ' ' // content of the deploy script here
                ]

With this payload the deploy-script will not be overrided and in the default deploy script the npm run build and further on the manifest.json is missing. In the forge-sdk and the forge api docs i cant find a way to initially set the deploy-script.

So i tried to only set the repository without installing it, and update the deploy-script afterwards:

           // Update repository
            $forge->updateSiteGitRepository($site->serverId, $site->id, [
                'provider'   => 'custom',
                'repository' => $repoSshUrl,
                'branch'     => $branchName,
            ]);

            // Update deployment script
            $forge->updateSiteDeploymentScript($site->serverId, $site->id, $this->getDeployScript());

            // deploy the site for the first time
            $forge->deploySite($site->serverId, $site->id);


But then i get following error on the deployment step fatal: not a git repository (or any of the parent directories): .git

Now i am a bit clueless and hope, anyone has done it and can give me a hint. Thanks in advandce

0 likes
1 reply
LaryAI's avatar
Level 58

To solve the issue of installing a custom Git repository and setting a custom deploy script using the Laravel Forge SDK, you need to ensure that the repository is properly initialized and the deployment script is correctly set before triggering the deployment. Here's a step-by-step solution:

  1. Initialize the Git Repository: First, ensure that the repository is correctly set up on the site. You can use the installGitRepositoryOnSite method, but make sure the payload is correctly formatted.

  2. Set the Deployment Script: After setting up the repository, update the deployment script to include any necessary build steps like npm run build.

  3. Deploy the Site: Finally, trigger the deployment.

Here's how you can achieve this:

// Initialize the Git repository on the site
$forge->installGitRepositoryOnSite($site->serverId, $site->id, [
    'provider'   => 'custom',
    'repository' => $repoSshUrl, // Ensure this is the correct SSH URL
    'branch'     => $branchName, // Ensure this is the correct branch name
    'composer'   => true, // Run composer install if needed
]);

// Update the deployment script
$forge->updateSiteDeploymentScript($site->serverId, $site->id, $this->getDeployScript());

// Deploy the site
$forge->deploySite($site->serverId, $site->id);

Key Points:

  • Repository Initialization: Ensure that the SSH URL and branch name are correct. The provider should be set to 'custom' if you're using a custom Git server.

  • Deployment Script: The deployment script should include all necessary commands to build and deploy your application. For example, if you need to run npm install and npm run build, make sure these commands are included in the script returned by $this->getDeployScript().

  • Error Handling: If you encounter the error fatal: not a git repository, it usually means the repository wasn't initialized correctly. Double-check the SSH URL and ensure that the server has access to the repository.

By following these steps, you should be able to set up the Git repository and deploy your site using the Forge SDK. If issues persist, consider checking the Forge logs for more detailed error messages.

Please or to participate in this conversation.