Install nginx web server & mysql & phpmyadmin on aws ubuntu 14
Install nginx web server & mysql & phpmyadmin on aws ubuntu 14
04/08/2016
Install wordpress
Mount disk in ubuntu with aws volume
08/08/2016
Show all

Restore web from aws S3 backup files

Install wordpress

Create EC2 and:

cd /var/tmp/
wget https://www.yanivp.net/01.sh
bash 01.sh

one command:

cd /var/tmp/ && wget https://www.yanivp.net/01.sh && bash 01.sh

Download from s3 backup files:

goto s3 bucket and download backup zip file & backup sql file
make files as public

EC2 Shell: cd /var/tmp/

download web.backup.files.zip: wget public-link.zip
download sql.backup.file.sql: wget public-link.sql
rename zip content file to web.zip: sudo mv /var/tmp/*.zip /var/tmp/web.zip
rename sql db file to db.sql: sudo mv /var/tmp/*.sql /var/tmp/db.sql
sudo apt-get install unzip
mkdir web && mv /var/tmp/web.zip /var/tmp/web
cd /var/tmp/web/ && sudo unzip web.zip && mv web.zip /var/tmp/
sudo rm -rf /var/www/html/*
sudo rm /var/www/html/.htaccess
sudo mv -v /var/tmp/web/var/www/html/* /var/www/html/

one command: ( change public-link.zip & public-link.sql )

cd /var/tmp/ && wget public-link.zip && wget public-link.sql && sudo mv /var/tmp/*.zip /var/tmp/web.zip && sudo mv /var/tmp/*.sql /var/tmp/db.sql && sudo apt-get install unzip && mkdir web && mv /var/tmp/web.zip /var/tmp/web && cd /var/tmp/web/ && sudo unzip web.zip && mv web.zip /var/tmp/ && sudo rm -rf /var/www/html/* && sudo mv -v /var/tmp/web/var/www/html/* /var/www/html/ && sudo mv /var/tmp/web/var/www/html/.htaccess /var/www/html/
Warning message: change s3 bucket links file to private!

Import mysql database

mysqladmin -u root -p create wordpress

sudo mysql -h localhost -u root -p --max_allowed_packet=1073741824 wordpress < /var/tmp/db.sql

show my ip

wget http://ipinfo.io/ip -qO -

Change website url in PHPmyAdmin ( only for a new domain )

logon to http://EC2_IP/phpmyadmin
wp_options
change to EC2_IP

by command: ( change domain-name )

sudo mysql -h localhost -u root -p wordpress

UPDATE wp_options SET option_value = replace(option_value, 'http://domain-name', 'http://EC2-IP') WHERE option_name = 'home' OR option_name = 'siteurl';

wp-config ( only for a new domain )

Change wp-config.php user & password & define(‘WP_HOME’,’http://EC2_IP’); define(‘WP_SITEURL’,’http://EC2_IP’);

sudo sed -i "/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );" /var/www/html/wp-config.php

sudo sed -i "/, false);/adefine( 'WP_HOME','http://EC2-IP' );" /var/www/html/wp-config.php

sudo sed -i "/, false);/adefine( 'WP_SITEURL','http://EC2-IP' );" /var/www/html/wp-config.php

sudo nano /var/www/html/wp-config.php
sudo chown -R www-data /var/www/html

Disable plugins ( only for a new domain )

sudo mv /var/www/html/wp-content/plugins/better-wp-security/ /var/www/html/wp-content/plugins/better-wp-security0
sudo mv /var/www/html/wp-content/plugins/protect-wp-admin/ /var/www/html/wp-content/plugins/protect-wp-admin0
sudo mv /var/www/html/wp-content/plugins/backupwordpress/ /var/www/html/wp-content/plugins/backupwordpress0
sudo mv /var/www/html/wp-content/plugins/updraftplus/ /var/www/html/wp-content/plugins/updraftplus0
sudo mv /var/www/html/wp-content/plugins/xml-sitemap-feed/ /var/www/html/wp-content/plugins/xml-sitemap-feed0
sudo mv /var/www/html/wp-content/plugins/addfreestats/ /var/www/html/wp-content/plugins/addfreestats0
sudo mv /var/www/html/wp-content/plugins/clicky-analytics/ /var/www/html/wp-content/plugins/clicky-analytics0
sudo mv /var/www/html/wp-content/plugins/backwpup/ /var/www/html/wp-content/plugins/backwpup0

one command:

(sudo mv /var/www/html/wp-content/plugins/better-wp-security/ /var/www/html/wp-content/plugins/better-wp-security0;sudo mv /var/www/html/wp-content/plugins/protect-wp-admin/ /var/www/html/wp-content/plugins/protect-wp-admin0;sudo mv /var/www/html/wp-content/plugins/backupwordpress/ /var/www/html/wp-content/plugins/backupwordpress0;sudo mv /var/www/html/wp-content/plugins/updraftplus/ /var/www/html/wp-content/plugins/updraftplus0;sudo mv /var/www/html/wp-content/plugins/xml-sitemap-feed/ /var/www/html/wp-content/plugins/xml-sitemap-feed0;sudo mv /var/www/html/wp-content/plugins/addfreestats/ /var/www/html/wp-content/plugins/addfreestats0;sudo mv /var/www/html/wp-content/plugins/clicky-analytics/ /var/www/html/wp-content/plugins/clicky-analytics0;sudo mv /var/www/html/wp-content/plugins/backwpup/ /var/www/html/wp-content/plugins/backwpup0) &
 FIX Permalink /%postname%/ 404 not found
sudo sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf 
sudo a2enmod rewrite
sudo service apache2 restart
one command:
sudo sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf && sudo a2enmod rewrite && sudo service apache2 restart

Go to admin login: http://ec2-ip/wp-admin

select setting and permalink choose Plain and Save Setting
select setting and permalink choose Post name and Save Setting

 FIX WP Memory Limit  ( only for a new domain )

sudo sed -i "/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );" /var/www/html/wp-config.php

FIX .hthaccess Parameters  ( only for a new domain )

sudo sed -i '/IfModule>/aphp_value upload_max_filesize 50M' /var/www/html/.htaccess
sudo sed -i '/IfModule>/aphp_value post_max_size 50M' /var/www/html/.htaccess
sudo sed -i '/IfModule>/aphp_value max_execution_time 500' /var/www/html/.htaccess
sudo sed -i '/IfModule>/aphp_value max_input_time 500' /var/www/html/.htaccess
sudo sed -i '/IfModule>/aphp_value max_input_vars 5000' /var/www/html/.htaccess

one command:

sudo nano /var/www/html/.htaccess

sudo sed -i '/IfModule>/aphp_value upload_max_filesize 50M' /var/www/html/.htaccess && sudo sed -i '/IfModule>/aphp_value post_max_size 50M' /var/www/html/.htaccess && sudo sed -i '/IfModule>/aphp_value max_execution_time 500' /var/www/html/.htaccess && sudo sed -i '/IfModule>/aphp_value max_input_time 500' /var/www/html/.htaccess && sudo sed -i '/IfModule>/aphp_value max_input_vars 5000' /var/www/html/.htaccess

Reference:https://www.yanivp.net//wpbeaches.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/

Change Domain & Fix url links ( only for a new domain )

Option 1:
download  WordPress Move plugin from https://www.yanivp.net//wordpress.org/plugins/wordpress-move/
open Migration Assistant  open print screen
open Change Domain Name  open print screen
and replace old domain with new domain open print screen

Option 2:
download  All-in-One WP Migration plugin from https://www.yanivp.net//wordpress.org/plugins/all-in-one-wp-migration/
export site with replace from https://www.yanivp.net/wp-content/uploads/ to http://EC2-IP/wp-content/uploads/ open print screen
import site open print screen

Clean up

Delete temp db “dbname” mysqladmin -u root -p DROP dbname;

Create Backup’s to aws S3

  1. create IAM user & aws cfg link
  2. mkdir /var/tmp/backup2s3
  3. sudo chown ubuntu /var/tmp/backup2s3/
  4. sudo apt-get -y install awscli
  5. sudo apt-get install zip
  6. sudo -i aws configure
  7. access key xxxx
  8. secret access key xxxx
  9. default region name [None]: eu-west-1
  10. default output format [None]: json
  11. zip all the web folder to zip file and exclude local backup folder
  12. backup database to file
  13. sync backup files to aws s3
  14. delete files older then 10 days in  /var/tmp/backup2s3/
  15. create Lifecycle in s3 bucket to delete files older then x days link & tool & video

one command: ( 11 – 15 ) replace user & password & database name &  s3 bucket name before run this command

sudo zip -r /var/tmp/backup2s3/web_`date +%d-%m-%Y-%H:%M`.zip /var/www/html/ -x '/var/www/html/wp-content/uploads/backups/*' && mysqldump --user=root --password='??password??' wordpress > /var/tmp/backup2s3/db_`date +%d-%m-%Y-%H:%M`.sql && sudo -i aws s3 sync /var/tmp/backup2s3/ s3://??bucket name??/??folder name?? && ls -d -1tr /var/tmp/backup2s3/* | head -n -10 | xargs -d 'n' rm -f

Bash File: replace user & password & database name &  s3 bucket name before run this command

#!/bin/bash

sudo zip -r /var/tmp/backup2s3/web_`date +%d-%m-%Y-%H:%M`.zip /var/www/html/ -x '/var/www/html/wp-content/uploads/backups_web/*'
mysqldump --user=root --password='??password??' wordpress > /var/tmp/backup2s3/db_`date +%d-%m-%Y-%H:%M`.sql
sudo -i aws s3 sync /var/tmp/backup2s3/ s3://??bucket name??/??folder name??
ls -d -1tr /var/tmp/backup2s3/* | head -n -10 | xargs -d 'n' rm -f

Create cron job:

sudo nano /etc/job2.sh
sudo chmod +x /etc/job2.sh
sudo chmod 775 /etc/job2.sh
sudo nano /etc/crontab
edit crontab to run every day at 11 pm: 0 23 * * * ubuntu /etc/job2.sh
tail -f /var/log/syslog | grep CRON
sudo rm /var/tmp/backup2s3/*
sudo service cron restart
sudo service rsyslog restart
Warning DELETE S3 folder sudo -i aws s3 rm s3://??bucket name??/??folder name??/ --recursive

Troubleshooting:

wordpress white screen of death: disable all plugins  sudo mv /var/www/html/wp-content/plugins plugins00

reset wordpress admin user password with phpmyadmin: Run SQL query:
UPDATE `wp_users` SET `user_pass`= MD5('yourpassword') WHERE `user_login`='yourusername';

reset MYSQL root user password:
sudo /etc/init.d/mysql stop
sudo mysqld –skip-grant-tables &
mysql -u root mysql
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;

Reference: https://www.yanivp.net//ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password

Comments are closed.