If you have been running your wordpress blog on a hosting provider and want to move for several reasons like slow performance , lack of control etc. , AWS EC2 would be a nice solution. Do not be afraid of not being familiar to the AWS. As it offers you free tier usage, you can assess AWS services for one long year :)
If you go on reading, I presume you want to move your wordpress content management system to the AWS EC2 which will not be a tough process.
- Take a backup of wordpress root directory (zip the content to decrease the size)
- Export wordpress database as *.sql dump file (zip the *.sql to diminish the size)
- Launch an instance on AWS
- Install lamp web server
- Upload the zip files, configure the database, edit wp-config.php
First of all, you ought to take backup of the wordpress database and wordpress root directory. If you are able to access your hosting by CPanel, you can take a backup of the wordpress root folder and export the wordpress database as *.sql file. If not, you may need to connect to the wordpress instance by using an ssh tool like putty. ZIP command can be used to archive all files and folders located under the wordpress root folder.
zip folder_name *
zip -r folder_name *
To unzip the zip file, you can use the unzip command .
MySQL commands can be run to export the database as *.sql file.
mysql -u root -p database_name > export_name.sql
To import the dump file, you just need to use “<” instead of “>” .
WinSCP is one of the most common tools which can be used to download the files to your desktop or upload the file to the instance run in EC2.
Now, you have the backup of your wordpress root directory and the dump file(the mysql database export). I won`t dive into details since it`s pretty easy to launch an instance on AWS. After the instance is ready, then follow the steps to install the web server called LAMP. If you do not want use, you do not need to install phpMyAdmin tool as it is indicated as optional in the document.
Next step is to upload files you prepared earlier to a directory in the instance. I have created a directory called tempfile under the /ec2-user/ path and uploaded two zip file into the directory. Unzip the database file to the same path.
There are few more steps left.
Login to mysql server by using mysql –u root –p .You are prompted to use root password when you run the command. Create the database which wordpress application will use.
mysql> CREATE DATABASE db_name;
You can use old database name for the new database. Close the mysql session.
Complete this step in mysql database export file: Edit the mysql dump file by using VI and insert IF NO EXISTS in database creation line(probably line 22). Otherwise, the dump import process tries to create the database which has already been created.
Import the mysql dump file by using the command shown below.
mysql -u root -p database_name < export_name.sql
Create mysql login and grant permission to it to use in wp-config.php file. Sample codes are shown below
To create a user:
mysql –u wordpressuser -p
To grant necessary permission to a user on wordpress database:
mysql> grant all privileges on wordpressdatabase.* to “wordpressuser”@”localhost” identified by “user password”;
You can use flush privileges; to obtain the permission immediately.
The new database is ready to use.
Unzip the wordpress root directory zip file(remember that you have unzipped the database file earlier) to /var/www/html directory. Edit the wp-config.php file by using the VI editor. You need to edit username, database name, password, connection string parameters. That’s all and it is time to test. Try to browse the wordpress blog by using either IPaddress or the cname record which points the instance. If it works well, change the DNS name to IP mapping.
If you choose a micro instance please read the note.
PS. The micro instance you have launched may probably not have a swap file. You need to add aswapfile to prevent MySQL crashes due to lack of memory.
- Run dd if=/dev/zero of=/swapfile bs=1M count=1024 (if you want add more, augment 1024 number)
- Run mkswap /swapfile
- Run swapon /swapfile
- Add this line /swapfile swap swap defaults 0 0 to /etc/fstab
- Run swapon –a ( swapoff –a to turn off)