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

squibby's avatar

Please Help Needed - provision custom server with laravel forge

Hi,

Having a headache with provisioning with forge then installing git repo.

This is what I do.

  1. Spin up my own EC2 server.
  2. Use Forge API to create a custom server in Forge and obtain a provisioning script.
  3. SSH to the server (via code) and run the provisioning script.
  4. 10 Minutes later the server is provisioned
  5. Then I try to install git repo either via api or forge UI and it just wont work. It says

Cloning into 'default'... Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

The main problem I think.. is step 3. If I manually SSH into the server myself and then run the script, after provisioning is complete I can install the git repo via the forge UI or via API. Only when I use code to SSH and run the script it wont install the repo.

I think its really weird that it wont install, because the provisioning completes. It sends me an email as normal and in Github the deploy key is set up.

I am using phpseclib to SSH into my server code below:


        // SSH to server
        $key = new RSA();
        $key->loadKey($myKeyFile);
        $ssh = new SSH2($serverIp);
            
        if(! $ssh->login('ubuntu', $key)) {
            throw new Exception('SSH exception - unable to gain access to server via SSH');
        }

        // Execute provisioning script
        $ssh->exec('the-script-obtained-from-forge-here');


This all executes and the server provisions. So what Am I doing wrong? I contacted Forge support and have been told to check my code, but i'm stuck. I cant understand why it will work when manully SSH but via phpseclib is doesn't.

If any anyone can help I will be really grateful.

Thanks.

0 likes
1 reply
squibby's avatar
squibby
OP
Best Answer
Level 8

Ok I worked it out.

Even though the deploy key was in github added by forge, they were not added to the known_hosts file. They should be added via this command: 'ssh-keyscan -H github.com >> /home/forge/.ssh/known_hosts' which i found inside the forge deploy script. For some reason even though it is run as part of the deployment script it is failing and thats why it wouldn't install.

Please or to participate in this conversation.