Create WordPress and MYSQL AMIs from Amazon Linux AMI.

Create WordPress and MYSQL AMIs from Amazon Linux AMI.

MYSQL AMI will be used to launch a remote private database.

  • Launch an instance with Amazon Linux AMI (ami-08706cb5f68222d09).
  • SSH into the instance and run the following commands.
#ssh -i key.pem -l ec2-user PUBLICIP
#sudo su

#yum install httpd -y
#wget https://wordpress.org/latest.tar.gz
#tar -xzf latest.tar.gz
#cp wordpress/* /var/www/html/

#yum update
#yum remove httpd*
#yum clean all
#yum upgrade -y

#yum install httpd24 -y
#yum install php70 php70-mysqlnd php70-imap php70-pecl-memcache php70-pecl-apcu php70-gd -y
#yum install mod24_ssl -y

#service httpd start

WordPress is almost ready...we will come back to it to provide the MySQL database details.

  • Launch another instance.
  • SSH into it and run the following commands:
#sudo su

Install MySQL server
#yum install mysql-server -y

Configure mysql server to start up automatically on reboot
#chkconfig mysqld on

Start the MySQL
#service mysqld start

Update password on your local MySQL server
#mysqladmin -u root password [new_password]


-----------ENBABLE REMOTE ACCESS---------------

Edit config so that it can serve as a remote database server.
#vi /etc/my.cnf
bind-address = 0.0.0.0

#service mysqld restart


login to MySQL:
#mysql -u root -p
[password in step 4]
>CREATE DATABASE wpdb;

>CREATE USER 'root'@'%' IDENTIFIED BY 'password';

>GRANT ALL PRIVILEGES ON *.* to root@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
>FLUSH PRIVILEGES;
>EXIT;


OR YOU CAN ALSO CREATE A REMOTE USER AND GRANT PRIVILEGES (BEFORE EXIT)
>CREATE USER 'ishan'@'localhost' IDENTIFIED BY 'redhat';

>CREATE USER 'ishan'@'%' IDENTIFIED BY 'redhat';

>GRANT ALL PRIVILEGES ON *.* to ishan@localhost IDENTIFIED BY 'redhat' WITH GRANT OPTION;

>GRANT ALL PRIVILEGES ON *.* to ishan@'%' IDENTIFIED BY 'redhat' WITH GRANT OPTION;

>FLUSH PRIVILEGES;


>EXIT;

MYSQL remote server is ready

  • Go back to WordPress instance.
#cd /var/www/html/
#cp wp-config-sample.php wp-config.php
#vi wp-config.php

  • Edit the lines with configured MySQL as shown:
No alt text provided for this image
  • Save this file.
  • Both instances are now ready. The first instance can act as a public WordPress server while the second instance can run as a remote private MySQL database.
  • Exit the instances and go to the options and create images.

Now when you launch instances using these AMIs, it will be preconfigured.

To view or add a comment, sign in

More articles by Ishan Singhal

Others also viewed

Explore content categories