Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jagveerdev/2c60a113249023fed4c5b6c4853bd10a to your computer and use it in GitHub Desktop.

Select an option

Save jagveerdev/2c60a113249023fed4c5b6c4853bd10a to your computer and use it in GitHub Desktop.

Startup steps for AWS Cloud9

These are the startup steps for AWS Cloud9. The Platform should be set to Ubuntu Server 18.04 LTS.

Git Config and global .gitignore file

  • Setup the git configuration variables
     git config --global user.name "Jagveer Singh"
     git config --global user.email "[email protected]"
     git config --global core.excludesfile "~/.gitignore"
     git config --global color.ui true
     git config --global push.default current
     sudo ln -s /bin/nano /usr/bin/nano
  • Add the git aliases by running this command
     curl https://gist.githubusercontent.com/pritdeveloper/703cb04659cd37d836fadbe0f02b0df6/raw >> ~/.gitconfig
  • Copy the .gitignore file by running the command
     curl https://gist.githubusercontent.com/pritdeveloper/acfd4edd5cc3f43cb6b5f3338acd9fdf/raw > ~/.gitignore

Install composer:

Install the composer package for running the composer command by running this command.

sudo apt install composer -y

This is optional and only needed if you want to run the composer command.

Enable rewrite mod

Enable the apache2 rewrite mod by running this command.

sudo a2enmod rewrite

Make the apache run as cloud9 ubuntu user

  • Open terminal and run this command:
     sudo vi /etc/apache2/envvars

hey hey hey use insert command here by click i then after write export APACHE_RUN_USER=ubuntu,export APACHE_RUN_GROUP=ubuntu click esc then :wq

  • Make the apache run user and group as ubuntu by changing these lines:
     export APACHE_RUN_USER=ubuntu
     export APACHE_RUN_GROUP=ubuntu

Make the aliases

  • Edit the ~/.basrc file by running this command:
     sudo vi ~/.bashrc
  • add this code
     if [ -f ~/.bash_aliases ]; then
     . ~/.bash_aliases
     fi
  • Create the .bash_aliases file with this command
     curl https://gist.githubusercontent.com/pritdeveloper/5cd890652c2da532efac5d4558971e7a/raw > ~/.bash_aliases
  • reload the terminal by running this command:
     . ~/.bashrc

Make the /home/ubuntu/environment as the web-root

  • Make the 000-default.conf file by running command:
     curl https://gist.githubusercontent.com/pritdeveloper/6f9eb3a67f9689011db6d6c1341e1323/raw | sudo tee /etc/apache2/sites-enabled/000-default.conf
  • Restart the apache server by running:
     sudo service apache2 restart

Install phpmyadmin and reset mysql password

  • To reset the mysql root password, follow this link.
  • To install phpmyadmin, simply run this command
     sudo apt install phpmyadmin -y
  • There is a Warning in phpmyadmin which can be fixed by editing file by running this command
     sudo vi /usr/share/phpmyadmin/libraries/sql.lib.php
     sudo vi /usr/share/phpmyadmin/libraries/plugin_interface.lib.php
  • goto line: 613, 551
  • replace the line with
     || (count($analyzed_sql_results['select_expr']) == 1
     if ($options != null && count((array)$options) > 0) {

Setup Inbound Rules (allow web traffic):

  • Click on the Manage EC2 Instance link in the top right of Cloud9 IDE and on the next screen click on the security group under the Description tab
  • Now click on the Inbound tab and click on Edit button.
  • Add new rules and set the Typeto HTTP and HTTPS and click Save

Set Elastic IP (make the website be opened on a permanent public link)

The elastic IP which are associated to an instance which is in stopped state are charged on an hourly basis. Please check the pricing before continue.

  • Open the AWS Management Console and Open the EC2 Service under top left Services dropdown.

  • Under the Network Security in left sidebar, Click on Elastic IPs.

  • Click on Allocate new address and then click on Allocate button.

  • Note the newely created IP address and then click on Close.

  • Now from the list select the newely created IP and then on top Actions dropdown, select the Associate address action.

  • Set the following:

    • Resource type: Instance
    • Instance: {Your newely created cloud9 instance}
    • Private IP: {the one shown in list}

    Keep the Reassociation checkbox unchecked

  • Click on Associate button.

  • Now you can open the website on this

Install SSL Certificate (optional) [make the website work on https]

There is a new tutorial for this https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04

  • Installing Certbot
     sudo add-apt-repository ppa:certbot/certbot
     sudo apt install python-certbot-apache
  • Obtaining an SSL Certificate
     sudo certbot --apache -d example.com -d www.example.com
  • Verifying Certbot Auto-Renewal
     sudo certbot renew --dry-run

Other way (long way)

  • Install the openssl package by running
     sudo apt-get install openssl
     sudo a2enmod ssl
     sudo service apache2 restart
  • Add directory to store certificate files
     sudo mkdir /etc/apache2/ssl

Make sure you have added a domain with A record pointing to the IPv4 Public IP of the instance after associating the Elastic IP with the instance.

  • Get a free ssl certificate on sslforfree.com and follow the instructions to download the sslforfree.zip file on a location on your computer.
  • Upload the sslforfree.zip file from your computer in the AWS IDE on the root of the workspace.
  • Copy and extract the zip file on the ssl directory by running this command:
     sudo cp /home/ubuntu/environment/sslforfree.zip /etc/apache2/ssl/sslforfree.zip
     sudo unzip /etc/apache2/ssl/sslforfree.zip
     sudo rm /home/ubuntu/environment/sslforfree.zip /etc/apache2/ssl/sslforfree.zip
  • Now you can open the website on https without any issues.

Keep in mind that the sslforfree.com provides ssl certificate for 3 months and you have to update the certificate in order to use it for longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment