Why in the world would you want to use Forge to manage your AWS instance? Because sometimes we just want a quick and clean way to get a Laravel instance up and running on AWS without a bunch of manual processes. Here’s a complete setup from A-F-B to connect your AWS to Forge then your Bitbucket repo. If you have any comments, questions or suggestions feel free to shoot me a message!
If you have had any issues connecting your AWS EC2 instance to Forge.Laravel and Bitbucket you’re not alone!
Instructions: Account Setup
If you have already set up your accounts and just want the nitty gritties, scroll down. Follow these steps to set up all your accounts you’ll need to connect AWS to Forge.Laravel & Bitbucket.
Set up your AWS EC2 instance, see detailed instructions below if you are not familiar with the process. I Forge tells you to set up an ubuntu instance so this is what I selected:
Here is the summary of the instance I chose.
DOWNLOAD THE SSH KEY AFTER YOU CLICK LAUNCH OR YOU ARE HOSED!!!
After you have set up your instance, will need to be able to SSH into the instance to connect Forge to AWS. If you are not familiar with AWS EC2 instances you may stumble through this portion and you probably shouldn't continue until you have enough knowledge about this subject. Create your instance with SSH and port 80 open (if you want the public to get to the box).
Private Key!! Once you reach the end of creating your instance be sure to download your private key, that is how we connect to Forge.Laravel.
One thing that held me up was using PUTTY to SSH into the AWS instance. At first, I connected using the public IP, that didn’t work well. Next, I read the instructions more and found you need to use the username@Public DNS (IPv4) as the host so for instance, in the case of AWS ubuntu is their default username. In the AWS documentation, it tells you the usernames for the other instance types (AMI).
Instructions: Connection Details
After you are able to successfully SSH into your AWS instance log into Forge.Laravel.com and DO NOT click on the AWS box in the middle, click the Custom VPS box.
Fill out all the input fields from your AWS instance screen:
One issue I ran into was I needed to be root in order to run the following script. run command sudo passwd root and set the root password, then run command su root and run the command Forge gives you.
After you click Create Server you will receive instructions to paste into your SSH/Putty session you should have open.
This is what it looks like if you copy that script into SSH and run it. Mine took just over 2 minutes so have patience.
Forge will look like this if things are going well:
This step took quite a while so go grab a snack or play something for a bit and it’ll be right as rain when you get back… well hopefully.. unless it crashes or the world implodes during that time.. you never know.
If you are wondering if anything is actually going on, check the main page of forge after you log in and it will give you the status of Provisioning, when it is done that will change to Active.
To check if it worked, load up the public IP address in the browser and you should see the phpinfo() echo’ed out.
Next connect your Bitbucket repo to your server. Click on the server in Forge.Laravel.com > scroll down to Active Sites > click on default >Click the Git Repository button. Select the Bitbucket option and fill out the form. You will however have to copy the ssh-rsa key before for it to work.
In the lower lefthand side, click your profile image > Bitbucket settings
Next, click on SSH under the Security menu heading:
If you have any SSH keys set up you’ll see them listed there. If not it will be empty. Click the Add Key button.
Enter whatever title you want then paste the key you were given in Forge and click Add Key.
After the last step you can then click Install Repository on Forge and then they are connected. If you enable Quick Deploy it will automatically update the server when you commit changes to your repo in that specific branch.
Also: If you do not have a public folder in your repo it will not serve the website so if your repo is naked or just has a readme file, you’ll get, “No input file specified.”. Add a public folder with an index.php file and you’re golden.
If your Provisioning never ends, it is most likely due to a key mismatch as I learned on my second install. Just delete the server on the forge side and redo the steps above.
If you keep getting an error when installing the repo on the forge side, it is either the branch you are naming doesn’t exist or your repo doesn’t exist. I was entering ghostbucket/nodejs.git into the repo, omit the .git part and then it works great.