Since c9.io has been forwarding new users to the new AWS Cloud9 service, I’ve been struggling for some time when I can finally move my development environment. Since I’ve been using c9.io for development for years and then publishing my projects via DigitalOcean, I thought, why not just use AWS Cloud9 with DigitalOcean? In this tutorial, I’ll show you how to do this without any major problems – it took me some time to make it work.
Prepare AWS account
If you have not already done so, please create an account with AWS and then log in (console.aws.amazon.com). Since the AWS Cloud9 service requires an IAM user instead of the main user, it is important to use the service with an IAM user. After successful login you open the IAM service and create a new user (in my case “main”). I have simply assigned the new user admin permissions, but you can customize it as you like. After the user has been created, you can log in with the new user using an own “Portal” link. Now you should be able to read the following at the top right: main @ 7268-xxxx-5200. Note that AWS Cloud9 is not yet available in all regions, therefore I navigate to EU Ireland.
Prepare DigitalOcean account
To establish a secure connection between AWS Cloud9 and DigitalOcean, DigitalOcean must know a public SSH key of your AWS account. To get it, please navigate to the AWS Cloud9 service in AWS and create a new SSH workspace. There you should be able to see your SSH key, which you copy and then add to your DigitalOcean account. Copy your SSH public key and paste it to your DigitalOcean account Dashboard > Security > SSH Keys > Add.
It is also necessary to create a local SSH key on your PC so that you can first connect to your droplet via CMD. See Add SSH Keys
Prepare Droplet for AWS Cloud9
Our two services AWS Cloud9 and DigitalOcean now know each other. We create a new Droplet in DigitalOcean. In this example I create a WordPress instance on Ubuntu. Before I create the droplet, I select both SSH keys, which I have added previously. The newly created Droplet is not yet fully executable with the Cloud IDE, because the following components are required:
- Another admin user than root which has access to SSH
- Node Package Manager (npm)
To set up the above component, please first connect to SSH with your droplet on your local computer and execute the following commands, see also One-Click WordPress.[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”connect.sh”]
Create admin user
In this tutorial I am using matzeeable as new username.[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”user.sh”]
The nano command edits the sshd_config file so you can add this line (AllowUsers matzeeable root) to allow SSH access for the newly created user (CTRL + X, type “Y” to save).
In order to test the new user right away, we now log in with it and set the correct permissions for the .ssh and /var/www/html folder. In addition, you need to add the public SSH keys to the newly created file ~/.ssh/authorized_keys so that the clients (in this case AWS Cloud9 and your local computer) can access this server with this new user again. Note: If you do not know the keys at the moment you can use the keys from your root access and copy them:[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”permissions.sh”]
Instsall NodeJS and NPM
In this tutorial I am using nvm to install NodeJS and the Node Package Manager:[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”npm.sh”]
After successful installation copy the path of your node installation to clipboard because this is needed later when creating the AWS Cloud9 SSH workspace. Last but not least we restart the SSH service:[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”verify.sh”]
Create AWS Cloud9 SSH workspace
Everything is ready and we can finally create the SSH Workspace. This is now very easy:
- User: The newly created user
- Host: The DigitalOcean Droplet IP
- Port: 22
- Environment path: The initial path (the tree on the left side of your IDE)
- Node.js binary path: The above copied
Create it and the IDE starts to load. It then starts an installation process. This may stop at some points, but I noticed that reloading the IDE and reinstalling it more often leads to success. Happy Coding!
If you encounter problems while installing plugins or updates with the following error message Could not create directory or FTP credentials login you can use the following. Add
define('FS_METHOD', 'direct'); to your wp-config.php file – this skips the FTP credentials input. Afterwards change the apache2 user to your username which you used in the above
If you want to create a error log file diretly in your workspace tree you can modify the
error_log value in your php.ini file to
/var/www/html/php_errors.log and also restart apache2.
The terminal does not scroll as expected? This can be an issue with tmux > 2.2. Please refer to this forum post or run the following commands:[gist id=”f23c54c271deef81e2c67a62bb86011e” file=”tmux.sh”]