Skip to content

Instantly share code, notes, and snippets.

@danferth
Last active May 1, 2019 16:48
Show Gist options
  • Select an option

  • Save danferth/28fd56ccb88cb939d79e8530897807d0 to your computer and use it in GitHub Desktop.

Select an option

Save danferth/28fd56ccb88cb939d79e8530897807d0 to your computer and use it in GitHub Desktop.
AWS EC2 C9 setup 2019

Create instance

Use AWS Cloud9 to create an EC2 instance

  • set to Ubuntu
  • once complete open IDE
  • create info.php and an index.php

Set up viewing the application from outside of the IDE browser

This also will set the view to an elastic IP

In AWS veiw EC2 > instances

  • click on instance and name it
  • note public IP and subnet

In tabs below instances

  • click link next to security goups
  • click tab for Inbound
  • click edit
  • Add Rule
type : Custom TCP Rule
Port Range : 8080
Source : Anywhere

Go to services and search VPC

  • once there click subnets
  • select the subnet from the note earlier
  • click on Network ACL tab
  • Look at inbound rules
  • if a rule doesn't already exsist where type is HTTP (8080)
  • create rule with
Type : Custom TCP Rule
Port : 8080
Source : 0.0.0.0/0
Allow/Deny : ALLOW

Allocating an Elastic IP

so IP does not change when restarting instance

  • visit Netsir & Security > Elastic IPs from the EC2 Dashboard
  • Click Allocate new address
  • IPv4 address pool : Amazon Pool
  • Close

Associate new Elastic IP

  • select Elastic IP
  • Actions > Associate Address
  • Resource Type : Instance
  • Instance : the instance
  • private IP : private IP of instance

Reboot instance from actions > instance state > reboot on instances page

You can now view the instance from http://[elastic IP]:8080

Set up LAMP

The instance should come with Apache, PHP, MYSQL already installed. But.. you never know..

Check if Apache installed

$ apache2 -v

Check if PHP installed

$ php -v

A few things to do to PHP

usually the server will look for index.html first if you want it to look for index.php first...

$ sudo vim /etc/apache2/mods-enabled/dir.conf

in file move index.php to front of list like below

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

then restart apache

$ sudo systemctl restart apache2

we may need some modules such as curl for google reCaptcha

See list of modules

$ sudo apt-cache search php- | less
//if php-curl is listed skip if not look into installing for version of PHP installed

Check if MySQL installed

$ mysql --version

MySQL set up

run

$ sudo mysql_secure_installation
  • set new password for root user
  • confirm new password
  • For the rest of questions, just type y and hit ENTER. This will remove anonymous user, disallow root user login remotely and remove test database.

Change authentication method for root user

change authentication method from auth_socket to mysql_native_password this will help with phpmyadmin

$ sudo mysql
//run to check the current authentication method
$ SELECT user,authentication_string,plugin,host FROM mysql.user;

If root is set to auth_socket under plugin

run this command to change the authentication to mysql_native_password

$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '[password]';
$ FLUSH PRIVILEGES;
// check again to make sure it worked
$ SELECT user,authentication_string,plugin,host FROM mysql.user;
$ exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment