Skip to content

Instantly share code, notes, and snippets.

@designviacode
Forked from suvozy/Setup.md
Last active August 29, 2015 14:27
Show Gist options
  • Save designviacode/25fcf43774b5695789f3 to your computer and use it in GitHub Desktop.
Save designviacode/25fcf43774b5695789f3 to your computer and use it in GitHub Desktop.
Setup AWS EC2 and RDS (php5.5, apache2.4, mysql5.5, phpmyadmin)

Launch an instance

http://docs.aws.amazon.com/AmazonVPC/latest/GettingStartedGuide/GetStarted.html

Security group

phpMyAdmin

Inbound

Type Protocol Port Range Destination
SSH TCP 22 0.0.0.0/0
HTTP TCP 80 0.0.0.0/0

Assign phpMyAdmin to the new EC2 instance and visit

http://YOUR_SERVER_IP

Setup EC2

chmod 400 key.pem
ssh -i key.pem ec2-user@YOUR_SERVER_IP

Root login

sudo -i

Update and install

yum -y update
yum install -y gcc make gcc-c++
yum install -y php55-mysqlnd php55 php55-xml php55-mcrypt php55-mbstring php55-cli mysql55 mysql55-server httpd24

-y will tell yum to say yes to all questions.

Start your engines

service httpd start
service mysqld start

MySQL Setup

/usr/bin/mysqladmin -u root password SUPERSECUREPASSWORD

Setup startup scripts for apache and MySQL

cd /etc/rc.d/rc3.d
rm K15httpd
rm K36mysqld
ln -s ../init.d/mysqld S30mysql
ln -s ../init.d/httpd S85httpd

Install phpMyAdmin

cd /var/www/html
wget https://files.phpmyadmin.net/phpMyAdmin/4.4.13.1/phpMyAdmin-4.4.13.1-english.tar.gz
tar -xzvf phpMyAdmin-4.4.13.1-english.tar.gz -C /var/www/html
mv phpMyAdmin-4.4.13.1-english phpmyadmin
rm -rf phpMyAdmin-4.4.13.1-english.tar.gz

check for updates: https://www.phpmyadmin.net/downloads/

We now need to add permission for this folder, find the user group (should be apache) with this command:

egrep 'User|Group' /etc/httpd/conf/httpd.conf

Which will return:

User apache
Group apache

And last, run this command to associate that user with the phpmyadmin folder:

chown -R apache.apache phpmyadmin/

Install Config

cd /var/www/html/phpmyadmin/
cp config.sample.inc.php config.inc.php
mkdir config
chmod o+rw config
cp config.sample.inc.php config/config.inc.php
chmod o+w config/config.inc.php

Setup Config

nano /var/www/html/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = '{^QP+-(3mlHy+Gd~FE3mN{gIATs^1lX+T=KVYv{ubK*U0V';

reference: http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator

Restart Server

service httpd restart

Setup phpMyAdmin

http://YOUR_SERVER_IP/phpmyadmin/index.php

with username root password SUPERSECUREPASSWORD

Remove config folder

rm -rf config

Setup RDS

Setup RDS with username awsuser password mypassword

Security group

rds

Type Protocol Port Range Source
MYSQL/Aurora TCP 3306 sg-abcdefgh (phpMyAdmin)

Connect to RDS

Edit Config

nano /var/www/html/phpmyadmin/config.inc.php
$cfg['Servers'][$i]['host'] = 'mydbinstance.abcdefghijkl.us-east-1.rds.amazonaws.com:3306'

Access phpMyAdmin

http://YOUR_SERVER_IP/phpmyadmin/index.php

with username awsuser password mypassword

phpinfo

nano /var/www/html/info.php
<?php phpinfo(); ?>
http://YOUR_SERVER_IP/info.php

Test db connection

nano /var/www/html/db_test.php
<?php
$link = mysqli_connect('mydbinstance.abcdefghijkl.us-east-1.rds.amazonaws.com', 'awsuser', 'mypassword', 'information_schema', 3306);
var_dump($link);
<?php
$link = mysqli_connect('localhost', 'root', 'SUPERSECUREPASSWORD', 'information_schema');
var_dump($link);
http://YOUR_SERVER_IP/db_test.php

#Git Deploy https://gist.github.com/oodavid/1809044

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