Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Gettings started with Cloud9 + EC2 + MySQL + phpMyAdmin

Prerequisits

Please create a Cloud9 instance in your favorite region. Also create a RDS MySQL instance.

Installing PHP 7.1

Remove current Apache & PHP

sudo yum remove httpd* php*

Install additional commonly used PHP packages for PHP 7.1

sudo yum install apache2 \ 
 php71 \
 php71-gd \
 php71-imap \
 php71-mbstring \
 php71-mysqlnd \
 php71-opcache \
 php71-pdo \
 php71-pecl-apcu \
 mysql-server

Go on with step 2 of this answer to make index.php file working: https://stackoverflow.com/a/40581436/5506547

Create document root public so we can edit in Cloud9

Change the document root to of sudo nano /etc/httpd/conf/httpd.conf:

DocumentRoot "/home/ec2-user/environment/public/"

Change the directory of /var/www/ to this:

<Directory "/home/ec2-user/environment/">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

Change the directory of /var/www/html/ to /home/ec2-user/environment/public/ and set AllowOverride: All. You can now put your public files to public. If there is a 403 error, you have to set the permissions:

sudo chmod 0755 /home/ec2-user/environment/
sudo chmod 0755 /home/ec2-user

Installing phpMyAdmin

cd /usr/share
wget https://files.phpmyadmin.net/phpMyAdmin/4.8.1/phpMyAdmin-4.8.1-all-languages.zip
unzip phpMyAdmin-4.8.1-all-languages.zip
mv phpMyAdmin-4.8.1-all-languages phpmyadmin
chmod -R 0755 phpmyadmin
sudo nano /etc/httpd/conf/httpd.conf

Insert the following after DocumetnRoot "/var/www/html"

Alias /phpmyadmin "/usr/share/phpmyadmin/"
<Directory "/usr/share/phpmyadmin/">
     Order allow,deny
     Allow from all
     Require all granted
</Directory>

Configure phpMyAdmin to access your RDS

cd phpmyadmin
cp config.sample.inc.php config.inc.php
nano config.inc.php

Remove the current server and add the following:

$cfg['Servers'][$i]['host']          = 'dev.*.us-east-1.rds.amazonaws.com';
$cfg['Servers'][$i]['port']          = '3306';
$cfg['Servers'][$i]['socket']        = '';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysql';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'config';
$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = '12345678';
sudo service httpd restart

AWS configuration:

Make sure you have put the following security group Inbound rules in your EC2 instance:

  • HTTP
  • HTTPS
  • MYSQL

Also make sure the EC2 and RDS instance are in the same VPC if the RDC is not publicly accessible. You have to use the same security grops, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.