Create a gist now

Instantly share code, notes, and snippets.

@suvozit /Setup.md
Last active Oct 30, 2017

What would you like to do?
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

lmon commented Dec 16, 2014

thank you!
(you have a typo: "Git Depoly" should be "Git Deploy") 😄

sudo yum install -y php55-mysqlnd php55 php55-xml php55-mcrypt php55-mbstring php55-cli mysql55 mysql55-server httpd24

sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"

What are the difference between these two scripts? currently, I'm using ec2 to host a Wordpress site with your server script to setup which is nice, but the script looks missed sth that "groupinstall" has. How can I do the groupinstall to connect the RDS plus install the phpmyadmin?? cuz I tried the groupinstall and it failed to connect the RDS and install phpmyadmin, please help.

Thank you =)

This is awesome, thank you! I've been struggling with getting php 5.5 running on ec2 and this process worked flawlessly.

RoyLiou commented Apr 16, 2015

So cool! thank you.

Very helpful, thank you.

Brilliant stuff.. thanks a lot

i am executing this command service mysqld start it getting error comman not unrecongnised service

How do I create an ALIAS for phpmyadmin, for security reasons

Thanks very much, A great help!!

Tyvm! On the last step, I tried http://YOUR_SERVER_IP/db_test.php with my ec2's url. The browser returns: object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(61) "rackspace.cakmjmk8ufvv.us-east-1.rds.amazonaws.com via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(10) "5.6.23-log" ["server_version"]=> int(50623) ["stat"]=> string(134) "Uptime: 8363 Threads: 2 Questions: 4473 Slow queries: 0 Opens: 81 Flush tables: 1 Open tables: 74 Queries per second avg: 0.534" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(74) ["warning_count"]=> int(0) }

What happened?

makkaba commented Apr 16, 2016

thanks a lot !!

Hey buddy, am having some issues can I hire you to set things up? the wordpress is already done, but not able to connect to existing database, please email: awesome(dot)info@creativefriends(dot)asia
thanks

jeffmcneill commented Jul 29, 2017

Install PhpMyAdmin from the Amazon EPEL Repository, after Enabling EPEL:

yum-config-manager --enable epel
yum install phpmyadmin

Edit the file /etc/httpd/conf.d/phpMyAdmin.conf and replace 127.0.0.1 with the ip address of the client.

nano /etc/httpd/conf.d/phpMyAdmin.conf

Restart the web server

service httpd restart

Test to see if it works

https://host.domain.tld/phpmyadmin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment